I can't find anything in the Swift book about io. Is there any generic protocol similar to Java's OutputStream or Go's Writer interface for writing a stream of bytes? If you are writing a class that returns a stream, do you need to write your own protocol or use an Objective C protocol?
To be clear am asking for a Swift native interface for this not because I avoiding using Objective C or Cocoa, but for a description of the expected behavior for Swift to Swift code going forward.
This is something the Swift docs are quiet about and I wanted to know more about so I looked into it.
There is a protocol, it's called
Streamable
:OutputStream
:write
allows an object to be written to.String
conforms to both, making it easy to write to and from:Writing to a file:
There is also
writeToUrl
.I assume those functions are all built on top of Cocoa streams, which have similar functionality: