0

我是 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>
4

2 回答 2

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;
}
于 2012-06-27T13:42:17.133 回答
0

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

于 2012-06-27T13:49:28.050 回答