Created
October 28, 2016 18:59
-
-
Save algal/aad06d2c78f7be01f901af5f18e1ccba to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// known-good. Xcode 8, Swift 3 | |
import XCPlayground | |
/// writes string s to a file in the playground shared directory and returns its URL | |
func write(string s:String, toPlaygroundSharedDataDirectoryFileWithName name:String) -> URL? | |
{ | |
let dirURL:URL = XCPlaygroundSharedDataDirectoryURL as URL | |
let fileURL:URL = dirURL.appendingPathComponent(name) | |
let path = fileURL.path | |
FileManager.default.createFile(atPath: path, contents: nil, attributes: nil) | |
guard let handle = FileHandle(forWritingAtPath: path) else { return nil } | |
defer { handle.closeFile() } | |
let data:Data = s.data(using: .utf8)! | |
handle.write(data) | |
return fileURL | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment