Changing Data in a Plist

与世无争的帅哥 提交于 2019-11-30 19:31:50

问题


Hey, alright so I have a .plist that looks like;

<plist version="1.0">
<dict>
 <key>Item 0</key>
  <dict>
    <key>Name</key>
    <string>Jero</string>
    <key>Initiative</key>
    <integer>0</integer>
    <key>EditThis</key>
    <false/>
 </dict>
</dict>
</plist>

In the app I have it so that when one of the rows (The data is put in a UITableView) is selected it pushes to a new view controller. I would like also to set the 'EditThis' boolean to yes, so the edit view controller can learn which to edit. However I can't seem to figure out how to change the value. Any help is much appreciated.


回答1:


Load the plist into a mutable dictionary:

NSMutableDictionary *plist = [NSMutableDictionary dictionaryWithContentsOfFile:@"file.plist"];
[plist setObject:[NSNumber numberWithBool:YES] forKey:@"EditThis"];
[plist writeToFile:@"file.plist" atomically:YES];


来源:https://stackoverflow.com/questions/1680367/changing-data-in-a-plist

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