I'm reading and writing to 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)
"".writeToFile(path, atomically: false, encoding: NSUTF8StringEncoding, error: nil)
The file will have cleared. – Smarten