how to add and retrieve data from plist programmatically

陌路散爱 提交于 2019-11-30 03:26:21

问题


hello all I am new to objective c and i want to insert data dynamically/programmatically into plist.please help me.Here is my plist structure

root
  |_Client1
        |_report1
             |_application1
             |_application2

        |_report2
             |_application3

  |_Client2
       |_report1

Now i want to add and retrieve data dynamically to application1,application2 in my plist please help me


回答1:


Reading content of .plist file ..

NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"league" ofType:@"plist"];
contentArray = [NSArray arrayWithContentsOfFile:plistPath];

Writing to .plist file.

NSMutableDictionary * myDictionary;
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"league" ofType:@"plist"];
[myDictionary writeToFile:plistPath atomically:YES];

Note that: Dictionary must contain plist objects (instances of NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary). And dictionary keys must be NSString objects



来源:https://stackoverflow.com/questions/5674011/how-to-add-and-retrieve-data-from-plist-programmatically

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