Experience is in C and I have searched for info on file i/o in swift 5 and find nothing. Lots of old examples but so out of date can't be fixed. Is there docs on file i/o somewhere? Opening new files, appending existing files etc? I don't mind reading, just can't find anything to read.
Firstly - you have access to C APIs by importing Glibc
(on linux) or Darwin
(on apple OSes), so if you just want to get up and running with APIs you know, you can do that.
Secondly - these kinds of things are intentionally left out of the standard library, and instead Foundation
provides things like I/O primitives and networking which work on all platforms Swift supports (and Windows). That's the better way. So you might want to have a look at its documentation to get a feel for everything it contains. Check out the links below.
- Foundation: documentation
- Foundation filesystem: documentation
There are lots of things that deal with files. FileHandle
is the lowest level, POSIX-y interface, but Data
also has init(contentsOf: URL, options: DataReadingOptions)
which can memory-map if appropriate.
Thanks Karl, in all my searching never went down the right trail...back in the 80's I had all the Inside Macintosh Volumes. Then no programming for years, now just for fun.
Dunno if this is in swift foundation, but it is in Appleโs: Apple Developer Documentation