nsuserdefaults

Saving bool to NSUserDefaults and using it in a if statement using Swift

好久不见. 提交于 2019-12-04 02:13:23
I am struggling to figure out how to do an if statement with a bool saved to NSUserDefaults using Swift. I believe I know how to save the bool to NSUserDefaults but a confirmation in that would be greatly appreciated. This is the Objective-C code I am trying to figure out how to use with swift. if(![[NSUserDefaults standardUserDefaults] boolForKey:@"onoroff"]) { [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"onoroff"]; } this is what I have so far in Swift... if NSUserDefaults.standardUserDefaults().objectForKey("onoroff") != nil{ NSUserDefaults.standardUserDefaults().setBool

How to use NSUbiquitousKeyValueStore and NSUserDefaults together

丶灬走出姿态 提交于 2019-12-04 00:53:51
问题 Documentation is not clear on how to use NSUbiquitousKeyValueStore with edge cases. If I want to set a value, I understand that I should set a value to both NSUserDefaults and NSUbiquitousKeyValueStore since iCloud could be disabled. However in my tests [NSUbiquitousKeyValueStore defaultStore] return a valid object even if iCloud is disabled (tested on Mac OS). Also, to my understanding is that if iCloud is enabled, NSUbiquitousKeyValueStore 's values are stored to disk (and available offline

trying to create Favorite Button for add items in favorite list

六眼飞鱼酱① 提交于 2019-12-03 23:09:40
问题 I'm trying to create favorite button on CollectionViewCell for saving items in favorite list. When i tapped on favorite icon button it successfully add selected cell item in array of favorite list class, and also shows in favorite list. When i tapped on favorite button it change its image according to values are already saved or not. When i'm trying to save favorite list array in NSUserDefaults it save and also show values when i retrieve it. But when i close my app from simulator and run

iPhone and NSUserDefaults

北城余情 提交于 2019-12-03 22:19:24
问题 In my viewWillLoad: method I'm currently doing something along these lines: - (void)viewWillAppear:(BOOL)animated { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if ( [defaults boolForKey:@"enabled_preference"] ) { ... } else { ... } [super viewWillAppear:animated]; } If I build and run the application before opening the preference pane (built using a normal Settings.bundle ) then the bool seems to be NO (or more probably nil ) rather than the default YES . However if I

iPhone: Not able to store NSMutableDictionary to NSUserDefaults

独自空忆成欢 提交于 2019-12-03 22:17:30
I am trying to implemen "Add to Favorites" functionality using NSMutableDictionary as I have to add multiple key-values. The following addToFavourites method always display Count=0 even after adding object to dictionary. I read this and getting nsdefaults into mutabledictionary(instead of mutable array) and setting resulted dictionary back to nsdefaults but not sure what's the problem. Any help would be really appreciated. Thank you. Edited: From this I came to know that I have to move data around mutable and immutable dictionary and then it worked fine! but still not able to synchronize

Why does NSUserDefaults fail to save NSMutableDictionary?

半腔热情 提交于 2019-12-03 21:39:56
问题 I’m trying to save a NSMutableDictionary with NSUserDefaults . I read many posts on the topic in stackoverflow... I also found one option that worked; however unfortunately it worked only once and then it started to save (null) only. Does anybody have a hint? Thanks Code to save: [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:dictionary] forKey:@"Key"]; [[NSUserDefaults standardUserDefaults] synchronize]; Code to load: NSMutableDictionary

Reading NSUserDefaults from helper app in the sandbox

混江龙づ霸主 提交于 2019-12-03 16:44:33
I found some resources on reading the NSUserDefaults of another application. Objective-C NSUserDefaults caching prevents another app from accurately reading changes NSUserDefaults: Is it possible to get userDefaults from another app? Apparently, it's not possible. However the questions firstly relate to iOS, and secondly the two apps are completely different. I have a LaunchAtLogin helper app. But it does some other tasks too. Therefore, the helper app should run always, but only start the main app if the BOOL in the NSUserDefaults is set. Is there a way I can achieve that? Since 10.7.4 you

Save and Load UISwitch state

你离开我真会死。 提交于 2019-12-03 14:12:44
问题 I want to save the swtich state and load it when the program restarted. [[NSUserDefaults standardUserDefaults] setBool:switchControl.on forKey:@"switch"]; [[NSUserDefaults standardUserDefaults] synchronize]; This is the saving part BOOL test= [[NSUserDefaults standardUserDefaults] boolForKey:@"switch"]; NSLog(@"%@",test?@"YES":@"NO"); if(test == YES) [switchControl setOn:YES animated:YES]; else [switchControl setOn:NO animated:YES]; This is the part that is need to be set the switch to its

Does NSUserDefaults get erased when an app gets updated?

一世执手 提交于 2019-12-03 12:43:28
In my App i am using NSUserDefaults to save some data. I have a doubt regarding this when i update the app in App Store, Will The Data in NSUserDefaults will remain same or it is removed. No, it will not be erased on updating NSUserDefaults will not be erased during update, but it will be removed when you uninstall an app. 来源: https://stackoverflow.com/questions/8208485/does-nsuserdefaults-get-erased-when-an-app-gets-updated

How to get an update NSUserDefault on iOS 4?

限于喜欢 提交于 2019-12-03 12:24:07
I am developing an iPhone application, I encounter a problem on the iOS4 because of multi task. This application has the default settings defined in a Settings.bundle. If I run my application then I left it (so it goes in the background). I'll change the settings and restarts the application (it comes out of standby and method: applicationDidBecomeActive () is called). Values in NSUserDefault are not updates, but when I leave the application and relaunch. The values are good. Does someone experience the same problem as me? Is what I'm doing something wrong? Thank you for your advice / help. I