开发者

Having problem to fetch/save settings.bundle value by code

开发者 https://www.devze.com 2023-02-03 08:33 出处:网络
I\'m facing difficulty in fetching/saving setting bundle preference file by code. I\'m a beginner. I just need to fetch/save default value of key \"VERSION 2\" by code. I want to use the value of this

I'm facing difficulty in fetching/saving setting bundle preference file by code. I'm a beginner.

I just need to fetch/save default value of key "VERSION 2" by code. I want to use the value of this key for my controllers to work. Thanks.

This data is in:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//App开发者_JAVA技巧le//DTD PLIST 1.0//EN" "apple.com/DTDs/PropertyList-1.0.dtd">;
<plist version="1.0">
    <dict>
        <key>DefaultValue</key> 
          <string>Karachi</string> 
        <key>Key</key>
          <string>version2</string> 
        <key>Title</key>
          <string>VERSION</string> 
        <key>Type</key>
          <string>PSTitleValueSpecifier</string>
    </dict>
</plist>


You do that by simply doing the following

NSUserDefaults *prefs - [NSUserDefaults standardUserDefaults]; //considering it's in the default settings.bundle
NSString *versionString = [prefs stringForKey:@"Key"];

You can use the following methods to get defaults

  • arrayForKey
  • boolForKey
  • dataForKey
  • dictionaryForKey
  • floatForKey
  • integerForKey
  • objectForKey
  • stringArrayForKey
  • stringForKey
  • doubleForKey
  • URLForKey
0

精彩评论

暂无评论...
验证码 换一张
取 消