I read and write a text file. There is an instance where I want to delete the contents of the file (but not the file) as a kind of reset. How can i do this?
if ((dirs) != nil) { var dir = dirs![0]; //documents directory let path = dir.stringByAppendingPathComponent("UserInfo.txt"); println(path) let text = "Rondom Text" //writing text.writeToFile(path, atomically: false, encoding: NSUTF8StringEncoding, error: nil) //reading let text2 = String(contentsOfFile: path, encoding: NSUTF8StringEncoding, error: nil) println(text2)
source share