I have edited a .plist
file. How I understood it: because of sandboxing it is only possible to read files inside the .playgrounds
file in a Resources
directory. But how is it possible to write the edited file to this folder?
// read file
let xmlPath: String = NSBundle.mainBundle().pathForResource("Settings", ofType: "plist")!
var xmlDictionary: [String : AnyObject] = NSDictionary(contentsOfFile: xmlPath) as Dictionary<String, AnyObject>
// editing file
// ...
// saving file
let saveDict: NSDictionary = xmlDictionary as NSDictionary
let savePath: String = xmlPath.stringByDeletingLastPathComponent.stringByAppendingPathComponent("Saved.plist")
saveDict.writeToFile(savePath, atomically: false) // ~> false
Whether savePath
nor xmlPath
is working, returns false
meaning no success.
It would be nice if I could replace the old (non-edited) version of the .plist
file, but saving to a new file would also be ok.
modifying files in the main bundle doesn't appear to be possible, see earlier question. What you can do is to save to the sandboxed application folders, the URLs for which can be retrieved like this:
The urls will display in the righthand side of the playground, then simply copy and paste into the Finder -> Go -> Go to Folder dialogue box.
GitHub Repo: For a full working example see this GitHub repo.