1
嗨鍵(可可/ iPhone SDK)創建
NSString *documentsDirectory = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Documents/myfolder"]];
NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:@"Favourites.plist"];
NSMutableDictionary *rootDict = [[NSMutableDictionary alloc] initWithContentsOfFile:writablePath];
[rootDict setValue:@"My Third PDF" forKey:@"Title"];
[rootDict writeToFile:writablePath atomically: YES];
和繼承人我的plist:
<plist version="1.0">
<dict>
<key>Rows</key>
<array>
<dict>
<key>SaveName</key>
<string>first.pdf</string>
<key>Title</key>
<string>My first PDF</string>
</dict>
<dict>
<key>SaveName</key>
<string>second.pdf</string>
<key>Title</key>
<string>My Second PDF</string>
</dict>
</array>
</dict>
</plist>
如何去增加一個像
<dict>
<key>SaveName</key>
<string>third.pdf</string>
<key>Title</key>
<string>My third PDF</string>
</dict>
我的plist(對象?)?謝謝!
優秀的答案謝謝你,我修改了它略低爲* \t的NSMutableDictionary * rootDict = [[的NSMutableDictionary頁頭] initWithContentsOfFile:writablePath]。 \t \t的NSMutableDictionary *第三=的NSMutableDictionary dictionaryWithObjectsAndKeys: \t \t \t \t \t \t \t @ 「third.pdf」,@ 「SAVENAME」, \t \t \t \t \t \t \t @ 「我的第三個PDF」,@ 「標題」 , \t \t \t \t \t \t \t無]; \t \t [[rootDict objectForKey:@「Rows」] addObject:third]; * – DexCurl 2011-03-01 22:43:17