零值读取settings.bundle

时间:2010-11-17 08:20:59

标签: iphone nsuserdefaults settings.bundle

在Resources组的Settings.bundle文件中,到目前为止,我只有一个PSGroupSpecifier,并且在PSMultiValueSpecifier中有这个XML代码:

     <dict>
        <key>Title</key>
        <string>First day of week</string>
        <key>Type</key>
        <string>PSMultiValueSpecifier</string>
        <key>Key</key>
        <string>firstDayOfWeek</string>
        <key>DefaultValue</key>
        <string>Sunday</string>
        <key>Values</key>
        <array>
            <string>Sunday</string>
            <string>Monday</string>
        </array>
        <key>Titles</key>
        <array>
            <string>Sunday</string>
            <string>Monday</string>
        </array>
    </dict>

在AppDelegate的didFinishLaunchingWithOptions方法中我得到了值,但是firstDayOfWeek总是返回nil值,你能看到代码中的任何错误吗?

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *firstDayOfWeek = [defaults objectForKey:@"firstDayOfWeek"];
NSLog(@"FIRST DAY OF WEEK: %@", firstDayOfWeek);

1 个答案:

答案 0 :(得分:1)

firstDayOfWeek没有任何密钥。
“firstDayOfWeek”是键Key的对象。

objectForKey的参数字符串必须是plist <key>yourKey</key>

中的键

尝试:

<key>firstDayOfWeek</key>
<string>DefaultValue</string>