写入.plist文件iphone / ipad?

时间:2011-05-03 14:23:45

标签: iphone ipad plist

    <dict>
        <key>Name</key>
        <string>Ramesh</string>
        <key>Address</key>
        <string>Delhi</string>
    </dict>

如何在plist文件中以及在任何特定父标记内的运行时写入此内容。

1 个答案:

答案 0 :(得分:0)

只需设置此词典,就可以将plist写入apps目录。

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"Name", @"Ramesh", @"Address", @"Delhi", nil];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"dictionary.plist"];
[dictionary writeToFile:path atomically:YES];