I am working to get the contents of an NSData instance written to a file. I am currently using an Xcode playground.
This is my code:
let validDictionary = [
"numericalValue": 1,
"stringValue": "JSON",
"arrayValue": [0, 1, 2, 3, 4, 5]
]
let rawData: NSData!
if NSJSONSerialization.isValidJSONObject(validDictionary) {
do {
rawData = try NSJSONSerialization.dataWithJSONObject(validDictionary, options: .PrettyPrinted)
try rawData.writeToFile("newdata.json", options: .DataWritingAtomic)
} catch {
// Handle Error
}
}
I have a file named newdata.json located in resources but when I check it there is nothing inside. I also tried deleting and seeing if the file will be created but it still doesn't work.