如何编写包含字典数组的plist

时间:2012-06-27 13:25:57

标签: objective-c plist

我是iPhone的新开发者。我在主要包中有一个plist文件(名为“Favorites”)。

我需要使用以下结构编写数据,用于20个字典项。 我怎么写?

<array>
<dict>
    <key>PubDate</key>
    <date>2011-08-12T23:15:12Z</date>
    <key>ImageName</key>
    <string>abc.png</string>
    <key>Title</key>
    <string>ABCDEF</string>
    <key>Description</key>
    <string>Suggestions?</string>
</dict>
<dict>
    <key>PubDate</key>
    <date>2011-08-12T23:15:12Z</date>
    <key>ImageName</key>
    <string>abc.png</string>
    <key>Title</key>
    <string>ABCDEF</string>
    <key>Description</key>
    <string>Suggestions?</string>
</dict>
<dict>
    <key>PubDate</key>
    <date>2011-08-12T23:15:12Z</date>
    <key>ImageName</key>
    <string>abc.png</string>
    <key>Title</key>
    <string>ABCDEF</string>
    <key>Description</key>
    <string>Suggestions?</string>
</dict>

2 个答案:

答案 0 :(得分:0)

好吧,不要指望人们为你写出所有的代码,但这可能接近你所寻找的。

//Put this where you want to write the data. add is the filename you want to save under
    [info writeToFile:[self saveFilePath:add] atomically:YES];

//Put this somewhere in your class
- (NSString*) saveFilePath: (NSString *) add
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *path = [paths objectAtIndex:0];
    NSString *filename = [path stringByAppendingPathComponent:add];
    return filename;
}

答案 1 :(得分:0)

我将建议你制作一个Java类型字典bcoz字典是不可变的,所以你创建它一次,你不能添加或删除对象。对于类似Java的字典,您需要使用NSMutableDictionary ....