2012-03-09 61 views
2

我是iOS開發新手,我想知道.plist文件如何在iOS中使用。通過給我一個如何讀寫.plist寫數據的例子,任何人都可以幫助我嗎?.plist文件如何在iOS中工作

+0

http://stackoverflow.com/questions/5853735/how-can-we-create-我們-自有的plist文件-IN-A-的Xcode項目 – 2012-03-09 13:06:02

回答

7

燁:

NSString *rootPath = [[NSBundle mainBundle] bundlePath]; 
NSString *pListPath = [rootPath stringByAppendingPathComponent:@"Settings.bundle/Root.plist"]; 
NSDictionary *pList = [NSDictionary dictionaryWithContentsOfFile:pListPath]; 

寫入文件是不是太硬或者:

NSDictionary *dict; 
NSData *data = [NSPropertyListSerialization dataWithPropertyList:dict format:NSPropertyListXMLFormat_v1_0 options:0 error:&error]; 
[data writeToFile:self.saveToPath atomically:YES];