Swift .writeToFile не обновляет файл JSON в mainBundle
Я пытаюсь получить простой словарь, обновить значение ключа и записать обратно в файл. По какой-то причине writeToFile не обновляет файл в основном комплекте.
код гласит:
let filename = "testFile"
if let path = NSBundle.mainBundle().pathForResource(filename, ofType: "json") {
var error: NSError?
let InputData: NSData? = NSData(contentsOfFile: path, options: NSDataReadingOptions(), error: &error)
var jsonDictionary: NSMutableDictionary = NSJSONSerialization.JSONObjectWithData(InputData!, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSMutableDictionary
jsonDictionary.setValue(1, forKey: "levelRow")
let options = NSJSONWritingOptions.PrettyPrinted
var outputData : NSData? = NSJSONSerialization.dataWithJSONObject(jsonDictionary, options: options, error: &error)
outputData?.writeToFile(path, atomically: true)
}
файл выглядит так:
{
"levelColumn" : 0,
"levelRow" : 0,
}
чтение и обновление работают нормально ... но файл не обновляет levelRow до 1?
заранее спасибо.