plist writing data inside dictionary

☆樱花仙子☆ 提交于 2020-01-11 13:56:32

问题


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.



来源:https://stackoverflow.com/questions/11497517/plist-writing-data-inside-dictionary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!