我有一个结构如下的 plist:
<dict>
<key>memos</key>
<array>
<dict>
<key>title</key>
<string>First Memo</string>
<key>content</key>
<string>Testing one two three</string>
<key>category</key>
<string>testing</string>
</dict>
<dict>
<key>title</key>
<string>Test</string>
<key>content</key>
<string>This is a test memo.</string>
<key>category</key>
<string>testing</string>
</dict>
</array>
</dict>
我正在将它读入这样的数组:
self.memos = [NSMutableArray array];
NSString *path = [[NSBundle mainBundle] pathForResource:@"Memos" ofType:@"plist"];
NSDictionary *tempDictionary = [NSDictionary dictionaryWithContentsOfFile:path];
NSArray *tempArray = [tempDictionary objectForKey:@"memos"];
for(id dict in tempArray) {
NSString *title = [dict objectForKey:@"title"];
NSString *content = [dict objectForKey:@"content"];
NSString *category = [dict objectForKey:@"category"];
Memo *m = [[Memo alloc] initWithTitle:title content:content category:category];
[self.memos addObject:m];
}
我的问题是:如何将新的备忘录(三个字符串的字典)添加到 plist(特别是我的 plist 中的备忘录字典数组)?