Skip to content

Instantly share code, notes, and snippets.

@algal
Last active October 28, 2016 19:05
Show Gist options
  • Save algal/186b5f979137854227782358e614814f to your computer and use it in GitHub Desktop.
Save algal/186b5f979137854227782358e614814f to your computer and use it in GitHub Desktop.
// kg: Xcode 8, Swift 3
extension FileHandle : TextOutputStream {
public func write(_ string: String) {
guard let data = string.data(using: .utf8) else { return }
self.write(data)
}
}
// now something like:
let url:URL = // url to file here
let path = url.path
guard let handle = FileHandle(forWritingAtPath:path) else { return }
defer { handle.closeFile() }
print(1,2,3,to:&handle)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment