[swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

Quinn "The Eskimo!" eskimo1 at apple.com
Sun Jun 5 04:27:06 CDT 2016

On 5 Jun 2016, at 02:25, Matthias Zenger <matthias at objecthub.net> wrote:

> I still don't understand if it's currently actually *possible* to use non C-based solutions in Swift which use streaming. I wanted to use NSFileHandle (for a use case that requires streaming) and realized that this is an API that cannot really be used in Swift because it's based on Objective-C exceptions.

Ah, yes, that’s definitely something you should be wary of.  I don’t know what the plan is for getting NSFileHandle to play nicely with Swift.  Maybe someone else will chime in.

> Are there any alternatives?

You could always use NSStream.

However, building Swift code on top of NSStream is about as difficult as building it on top of UNIX system calls (open/close/read/write) or stdio (fopen/fclose/fread/fwrite), so if you need streaming file I/O you might as well do that.

Give it a go and let us know if you get stuck.

Finally, as has been mentioned on this thread already, it’s easy to imagine a Swift streaming file I/O that’s /much/ better than these options, although AFAIK there are no concrete plans for that.

Share and Enjoy
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

More information about the swift-users mailing list