func writeToFile(content: String, fileName: String) {
let contentToAppend = content+"\n"
let filePath = NSHomeDirectory() + "/Documents/" + fileName
//Check if file exists
if let fileHandle = NSFileHandle(forWritingAtPath: filePath) {
//Append to file
fileHandle.seekToEndOfFile()
fileHandle.writeData(contentToAppend.dataUsingEncoding(NSUTF8StringEncoding)!)
}
else {
//Create new file
do {
try contentToAppend.writeToFile(filePath, atomically: true, encoding: NSUTF8StringEncoding)
} catch {
print("Error creating \(filePath)")
}
}
}
I have that code which allows me to call this function and it writes to a file. Now im stuck as to how can I read this File. I'd like to have this display the files contents inside a multi line Text box. Can someone help me with a Read function for this code?