plist writing data inside dictionary

2020-05-08 21:30发布

问题:

Is it possible to edit values in our pList file in bundle or in our resources through code? This means that my plist file is NOT created programmatically and I want to edit its values programmatically.

回答1:

In your app bundle, no: you can't write files inside your app bundle.

However, you can copy the file to the Documents or Library directory of the app sandbox upon the first launch on your app, then edit the plist file from there -- wheter it was created by code or by hand is unimportant.



回答2:

I did something like this in my app. I created a plist which was basically a bunch of levels for my game. Each level was an array, with a whole bunch of different attributes like NSNumbers and NSStrings, etc. I add the original plist to my app bundle, but then when the user first launches the app, I create a copy of the plist and store it as a dictionary with Core Data. Then I can load and save all my data into the Core Data copy of the plist.

All the changes you make to the plist are saved in the Core Data, but the original plist is unchanged, so you have to make sure that once you have a saved game file, you load that instead of the plist. the plist only ever gets read once.



回答3:

try with this link. You can update the values in plist as will as add & delete too.