Created
October 10, 2017 14:49
-
-
Save mike-neko/6149430f06501b5db9c89aeaf103d5e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func write(url: URL, text: String) -> Bool { | |
guard let stream = OutputStream(url: url, append: true) else { | |
return false | |
} | |
stream.open() | |
defer { | |
stream.close() | |
} | |
guard let data = text.data(using: .utf8) else { return false } | |
let result = data.withUnsafeBytes { | |
stream.write($0, maxLength: data.count) | |
} | |
return (result > 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment