nsuserdefaults

Using NSUserDefaults for storing UISwitch state

爱⌒轻易说出口 提交于 2019-12-02 04:47:42
I am trying to persist the UISwitch state in my settings view of my application. Basically it is a UITableView and contains a few switches to get the user preferences. The below code explains how the switches are constructed (only one switch construct is given below, others are also constructed the sameway). if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SomeIdentifierB] autorelease]; if (syncStartupSwitch) { syncSwitch.on = YES; }else { syncSwitch.on = NO; } [syncSwitch addTarget:self action:@selector(syncAtStartup:) forControlEvents

iPhone: preserve NSUserDefaults values when application is killed

前提是你 提交于 2019-12-02 04:40:40
I am trying to implement "Add to Favorites" functionality using NSUserDefaults. So far I have written following code. - (void)favouriteButtonClicked:(id)sender { favselected = !favselected; // favselected is BOOL property MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; NSString* viewname = @"custom"; if(favselected) { [favButton setBackgroundImage:[UIImage imageNamed:@"selected.png"] forState:UIControlStateNormal]; [appDelegate addTOFavourites:self.ViewID viewType:self.ViewType]; } else { [favButton setBackgroundImage:[UIImage imageNamed:@"unselected

How to set Dictionary in NSUserDefault in swift?

随声附和 提交于 2019-12-02 04:24:05
I've a mutable dictionary (in form of [Int:Int]) and want that to save it. I would use NSUserDefaults like that: var myDic: NSMutableDictionary = [:] myDic = [1:2] NSUserDefaults.standardUserDefaults().setObject(myDic, forKey: "myDic") but with that I get an error: Thread 1: signal SIGABRT I have no idea why. setObject(_:forKey:) can’t accept Dictionary with a key which is integer type. The method requires property-list objects, but myDic = [1:2] is not property-list object. There are two documents about it. setObject(_:forKey:) of NSUserDefaults The value parameter can be only property list

iPhone's NSUserdefaults is a database or plist

一笑奈何 提交于 2019-12-02 04:03:56
I am not able to get NSUserDefaults concepts properly. Is that a database of plist file ? It's a key-value store that is persisted between restarts of your application. How it's implemented has little bearing on how you use it. I don't know if it's different on the iPhone OS (which i don't believe) but in Mac OS X is it a plist file in your Library/Preferences folder. Pretty sure it's the same on iPhone OS/iOS 来源: https://stackoverflow.com/questions/3178115/iphones-nsuserdefaults-is-a-database-or-plist

Specifically detailing what defaults have changed on NSUserDefaultsDidChangeNotification

大兔子大兔子 提交于 2019-12-02 02:23:53
问题 I'm starting to get into the inner sanctum of NSUserDefaults to the point where I can now successfully intercept an NSUserDefaultsDidChangeNotification notification using a supplied selector plus NSNotification object as a parameter. However, the returned NSNotification object does not appear as I had expected. What I was expecting was: 1) Receive NSUserDefaultsDidChangeNotification from the notification centre. 2) Interrogate the returned supplied NSNotification object for user info

Objective-C NSUserDefaults caching prevents another app from accurately reading changes

拜拜、爱过 提交于 2019-12-02 01:38:52
I have one application that sets preferences. It uses those prefs, and so does another application. When I use the following code in the second application, it reads the preferences correctly once. NSUserDefaults* settings = [NSUserDefaults standardUserDefaults]; [settings addSuiteNamed:@"com.WVS.Wrestling-Tools"]; [settings synchronize]; // this just a shot in the dark.. didn't work [self setScoreboardIndex:[settings integerForKey:@"matName"]]; On subsequent calls of the same code, I get the [settings integerForKey:@"matName"] is always the value that was first read. In the first application,

NSUserDefault with App Group is not working in iOS 8 Beta3

戏子无情 提交于 2019-12-02 01:01:37
问题 I have to save Boolean Value to NSUserDefault in my App with custom keyboard extension and share with App Group. My Code is worked in iOS 8 Beta1. self.defaults = [NSUserDefaults standardUserDefaults]; if([self.defaults boolForKey:@"BlackKey"]) { NSLog(@"Black"); } else { NSLog(@"White"); } But Not in iOS 8 Beta3. When i retrieve Boolean value from NSUserDefault , it's return nothing and i can't load from custom keyboard extension. I have also tried with initWithSuiteName in NSUserDefault .

Save MKPolyline as NSData in NSUserDefaults

こ雲淡風輕ζ 提交于 2019-12-02 00:25:25
问题 My iOS application needs to store an MKPolyline inside of an NSUserDefault . I've been doing a lot of research, and I now know that: NSUserDefaults are a subclass of NSCoder MKPolyline is not a subclass of NSCoder As a result, it is rather difficult to save a polyline to nsuserdefaults. I have attempted to convert the MKPolyline into NSData: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSData *data = [NSKeyedArchiver archivedDataWithRootObject:routeLine]; // routeLine is

Save MKPolyline as NSData in NSUserDefaults

坚强是说给别人听的谎言 提交于 2019-12-02 00:05:53
My iOS application needs to store an MKPolyline inside of an NSUserDefault . I've been doing a lot of research, and I now know that: NSUserDefaults are a subclass of NSCoder MKPolyline is not a subclass of NSCoder As a result, it is rather difficult to save a polyline to nsuserdefaults . I have attempted to convert the MKPolyline into NSData: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSData *data = [NSKeyedArchiver archivedDataWithRootObject:routeLine]; // routeLine is an MKPolyline [defaults dataForKey:@"key"]; [defaults synchronize]; When I try to convert the polyline

How to save and retrieve NSObject class using NSUserDafaults in iOS

送分小仙女□ 提交于 2019-12-01 23:55:07
Hi I want to save and retrieve NSObject class using NSUserDefaults for that I wrote below code but I am getting exception like below Terminating app due to uncaught exception ' NSInvalidArgumentException ', reason: 'Attempt to insert non-property list object for key DATA' For saving :- SavingBean*savingbean = [[SavingBean alloc]init]; [savingbean savingData:userName.text :passWord.text]; NSUserDefaults * defaults = [[NSUserDefaults alloc]init]; [defaults setObject:savingbean forKey:@"DATA"]; For retrieving:- defaults = [[NSUserDefaults alloc]init]; savingbean = [defaults objectForKey:@"DATA"];