如何按键类型编辑plist文件

时间:2013-04-28 14:25:58

标签: objective-c xcode cocoa plist

我想在“prefPlist”变量中添加一些具有相对类型的键的plist文件。

示例内容必须是:

<dict>
    <key>App Version</key>
    <string>Beta 1</string>
    <key>Configuration Type</key>
    <integer>7</integer>
    <key>Creation Date</key>
    <date>27 04 2013, 03:00</date>
    <key>Want some milk?</key>
    <true/>
</dict>

第一个键必须是字符串类型,第二个键必须是整数类型,第三个键必须是日期时间类型,第四个键必须是布尔值。

我该怎么做?

2 个答案:

答案 0 :(得分:0)

<key>prefList</key>
<array>
  <string>string</string>
  <string>integer</string>
  <string>date</string>
  <string>boolean</string>
</array>

答案 1 :(得分:0)

利玛:

您应该能够阅读支持的HERE

的NSDictionary和NSMutableDictionary消息

与此同时,似乎你想要使用,作为一个例子:

NSString *source = [[NSBundle mainBundle] pathForResource:@"FileName ofType:@"plist"];
myDictionary = [[[NSDictionary alloc] initWithContentsOfFile:source] mutableCopy];

这当然假设plist在你的捆绑中。在使用字典加载之前,请使用FileManager到您的沙箱文档或其他地方以获取正确的位置。