我正在尝试保存两个字符串。一个字符串需要在 pList 中保存为 ARRAY 类型,第二个字符串需要在 Array 中保存为 String。
我可以使用以下代码:
[字典 setObject:(id)anObject forKey:(id)aKey>]
但它没有正确保存它。我可以将其中一个字符串转换为数组,但它仍然无法正常工作。
将数组保存到 pList 的正确方法是什么?
这是我的 pList 的样子:
<dict>
<key>Test One</key>
<array>
<string>A13#</string>
</array>
<key>Another Test</key>
<array>
<string>1111111111</string>
</array>
<key>Test Three</key>
<array>
<string>2222222222</string>
</array>
<key>Final Test</key>
<array>
<string>3333333333</string>
</array>
</dict>
这是我用来尝试的方法
-(void)writeToFile:(NSString *)s1{
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:@"saved" ofType:@"plist"];
NSMutableDictionary *dictionary = [[[NSDictionary alloc] initWithContentsOfFile:plistPath] mutableCopy];
NSString *tempString = [NSString stringWithFormat:@"1234567"];
[dictionary setObject:tempString forKey:s1];
[dictionary writeToFile:plistPath atomically:YES];
}