更新字典,保存在plist中

时间:2011-10-27 08:36:00

标签: plist ios5 nsdictionary

如果我尝试在我的词典中添加一个新条目(plist),它就不起作用。编辑没问题。我认为问题是,我如何尝试添加条目。

如果我删除以“setObject”开头的行,则返回YES。

我的代码如下:

 NSMutableDictionary *updateDict = [[self.plist objectForKey:@"comments"]mutableCopy];

 NSMutableDictionary *tmpDict = [[[NSMutableDictionary alloc]init]autorelease];  
 [tmpDict setObject:comment forKey:@"comment"];
 [tmpDict setObject:author forKey:@"author"];
 [tmpDict setObject:car forKey:@"car"];
 [tmpDict setObject:part forKey:@"part"];
 [tmpDict setObject:date forKey:@"date"];

 [updateDict setObject:tmpDict forKey:[NSNumber numberWithInt:[updateDict count]+1]];

 [self.plist setObject:updateDict forKey:@"comments"];
 if([self.plist writeToFile:self.plistPath atomically:YES]) {
return YES;
 }
 else {
     return NO;
 }

self.plist是plistPath上文件的本地副本。我的plist的结构看起来像:

https://img.skitch.com/20111026-tcjxp9ha4up8ggtfjy7ucgqcqe.png

我正在为iPad上的iOS 5.0开发。

希望这会有所帮助

0 个答案:

没有答案