[swift-users] Pure Swift, cross platform way to open, read/write files?

Kwame Bryan kwame.bryan at gmail.com
Mon Dec 7 21:51:41 CST 2015

Hi Greg, you’ll need to do something like the following.
#if os(Linux)
    import Glibc
    import Darwin
Also, take a look at this blog post. http://blog.krzyzanowskim.com/2015/12/04/swift-package-manager-and-linux-compatible/ <http://blog.krzyzanowskim.com/2015/12/04/swift-package-manager-and-linux-compatible/> Hope this helps.


> On Dec 7, 2015, at 10:47 PM, Greg Skluzacek via swift-users <swift-users at swift.org> wrote:
> Hi new to Swift and I am really excited that Apple has open sourced it! I use macs at home an Linux at work, so now I may actually be able to develop in one language on both platforms (and not use Java).
> That being said, is there a way open a file for either reading line by line and writing line by line that is done purely in Swift and is cross platform.
> I did go through the Getting Started page and saw that one was able to import Glibc on Linux which implements the C fopen, etc., but when I tried to import it in the REPL on OS X, I got the error:
> repl.swift:1:8: error: no such module 'Glibc'
> import Glibc
>        ^
> swift --version returns:
> Chateau-Louise:/ gskluzacek$ swift --version
> Apple Swift version 2.1 (swiftlang-700.1.101.6 clang-700.1.76)
> Target: x86_64-apple-darwin14.5.0
> Chateau-Louise:/ gskluzacek$ 
> Thanks,
> -- Greg
>  _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20151207/b1b0f0cd/attachment.html>

More information about the swift-users mailing list