Created
June 7, 2014 10:33
Revisions
-
frozzare created this gist
Jun 7, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ import Foundation class File { class func exists (path: String) -> Bool { return NSFileManager().fileExistsAtPath(path) } class func read (path: String, encoding: NSStringEncoding = NSUTF8StringEncoding) -> String? { if File.exists(path) { return String.stringWithContentsOfFile(path, encoding: encoding, error: nil)! } return nil } class func write (path: String, content: String, encoding: NSStringEncoding = NSUTF8StringEncoding) -> Bool { return content.writeToFile(path, atomically: true, encoding: encoding, error: nil) } } let read : String? = File.read("/path/to/file.txt") println(read) let write : Bool = File.write("/path/to/file2.txt", content: "String to write") println(write)