I'm actually not sure whether I'm not able to read or unable to write. I'm pretty sure writing works. I'm using Swift.
Here are my project files.
I'm trying to write an array of arrays to a file, and then read that array of arrays when the app launches. Here's my code for writing and reading, respectively. listOfTasks
is my array of arrays variable.
Writing:
let cocoaArray : NSArray = listOfTasks
cocoaArray.writeToFile(String(fileURL), atomically: true)
Reading:
listOfTasks = NSArray(contentsOfFile: String(fileURL)) as! [Array<String>]
fileURL
:
let documentsDirectory = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).last
let fileURL = documentsDirectory!.URLByAppendingPathComponent("file.txt")
I'm happy to provide additional information as necessary. Thanks in advance!