Search code examples
iosarraysswiftwritetofile

WriteToFile not Working Swift


I've been stuck with this problem for hours. I tried writing the class in Objective C, Swift, logging the output of the Array (Which is not nil and has no problems at all if logged), even using NSURL to use writeToFile. I cleaned the project and tested on iOS Simulator and on an iOS Device. This exact code works in a different class, but not in this one. Any help would be much appreciated...

    let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
    var docs: String = paths[0] as String
    let responseData = docs.stringByAppendingPathComponent("myOwnData.plist")
    let test = self.tweetsArray!.writeToFile(responseData, atomically: true)
    println(test)

Solution

  • I tested the code with let array: NSArray = ["abc"] added at the beginning, and it worked. OP solved it by adding self.tweetsArray = NSArray() at the top.