#pragma mark - bundle下——即工程內plist文件內容的獲取及修改
#pragma mark 讀取
NSString * bundlePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"plist"];
NSMutableDictionary * data1 = [[NSMutableDictionary alloc] initWithContentsOfFile:bundlePath];
NSLog(@"%@", data1);
#pragma mark 添加
[data1 setObject:@"內容" forKey:@"關鍵字"];
[data1 setObject:@"hahaa" forKey:@"ccc"];
[data1 setObject:@"afee" forKey:@"aaaaa"];
#pragma mark - 操作沙盒內的plist文件
//獲取沙盒下的Documents目錄
NSArray * pathsArray=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString * plistPath = [pathsArray objectAtIndex:0];
//得到完整的文件名
NSString * filename=[plistPath stringByAppendingPathComponent:@"test.plist"];
//內容寫入
[data1 writeToFile:filename atomically:YES];
//讀取
NSMutableDictionary * data = [[NSMutableDictionary alloc] initWithContentsOfFile:filename];
NSLog(@"data1:%@", data);
本文檔用于代碼內容展示