cocoa touch - settings bundle - default value behaviour? -
i have created settings bundle single preference value, text field default value.
when application launches , retrieve value null. have manually code value use before user has provided value?
also if user preferences screen , enters text field leave without making changes value not set ... user has change value saved, correct?
no, don't that.
there's function this:
id userdefaults = [nsuserdefaults standarduserdefaults]; [userdefaults registerdefaults: defaultsettings]; you can build parameter iterating sub keys of preferencespecifiers in settings plist file.
something this:
- (nsdictionary *)readdefaultsettingsfromplist: (nsstring *)inpath; { id mutable = [nsmutabledictionary dictionary]; id settings = [nsdictionary dictionarywithcontentsoffile: inpath]; id specifiers = [settings objectforkey: @"preferencespecifiers"]; (id prefitem in specifiers) { id key = [prefitem objectforkey: @"key"]; id value = [prefitem objectforkey: @"defaultvalue"]; if ( key && value ) { [mutable setobject: value forkey: key]; } } return [nsdictionary dictionarywithdictionary: mutable]; }
Comments
Post a Comment