nsuserdefaults

NSInternalInconsistencyException with NSUserDefaults when using method setValue: forPath

余生长醉 提交于 2020-01-07 08:09:57
问题 My code is as follows: NSMutableDictionary *configure = [[NSUserDefaults standardUserDefaults] objectForKey:@"configure"]; if (!configure){ configure = [NSMutableDictionary dictionary]; [configure setValue:[NSMutableDictionary dictionary] forKeyPath:@"select"] ; [configure setValue:[NSMutableDictionary dictionary] forKeyPath:@"select.around"]; [configure setValue: @"All" forKeyPath:@"select.around.name"]; [[NSUserDefaults standardUserDefaults] setObject:configure forKey:@"configure"]; [

Save data of a Label in swift

时光毁灭记忆、已成空白 提交于 2020-01-06 20:54:34
问题 I have a TextField in my settingsController that i can modify selecting a name from a pickerView, the problem is this : when i change the text of my textField i also change the text of a label in another controller, it work but when i close and reopen my app the label is empty, i can't find a way to save the text that i give it with the pickerView. My code in the settingsController override func viewDidLoad() { super.viewDidLoad() var defaults: NSUserDefaults = NSUserDefaults

NSMutableArray not saved NSUserDefault

◇◆丶佛笑我妖孽 提交于 2020-01-06 18:12:02
问题 I'm trying to save a NSMutableArray with NSUSerDefault and then open the array. Here some code: -(IBAction)btnSave{ Class *aClass = [[Class alloc]init]; aClass.idClass=@"aaaxxx"; aClass.nameClass=@"hello"; [myArray addObject:aClass]; NSUserDefaults *arrayDefault=[NSUserDefaults standardUserDefaults]; [arrayDefault setObject:myArray forKey:@"savedArray"]; [arrayDefault synchronize]; } and - (void)viewDidLoad { [super viewDidLoad]; myArray=[[NSMutableArray alloc]init]; NSMutableArray

NSMutableArray not saved NSUserDefault

只谈情不闲聊 提交于 2020-01-06 18:10:08
问题 I'm trying to save a NSMutableArray with NSUSerDefault and then open the array. Here some code: -(IBAction)btnSave{ Class *aClass = [[Class alloc]init]; aClass.idClass=@"aaaxxx"; aClass.nameClass=@"hello"; [myArray addObject:aClass]; NSUserDefaults *arrayDefault=[NSUserDefaults standardUserDefaults]; [arrayDefault setObject:myArray forKey:@"savedArray"]; [arrayDefault synchronize]; } and - (void)viewDidLoad { [super viewDidLoad]; myArray=[[NSMutableArray alloc]init]; NSMutableArray

Saving NSMutableArray with NSUserDefaults in Swift Returns Nil

谁说我不能喝 提交于 2020-01-06 13:52:16
问题 I have a NSMutableArray . Here is how I save it with NSUserDefaults : var defaults = NSUserDefaults.standardUserDefaults() defaults.setObject(downloadedFile as NSMutableArray, forKey: "myKey") And here how I retrieve it: var downloadedFilesFromUserDefaults:NSMutableArray = defaults.objectForKey("myKey") as NSMutableArray 回答1: take look at this and try to save you array like this! as this worked perfectly! var arr:NSMutableArray = NSMutableArray(objects: "ASD","aSd") NSUserDefaults

Saving NSMutableArray with NSUserDefaults in Swift Returns Nil

拜拜、爱过 提交于 2020-01-06 13:50:34
问题 I have a NSMutableArray . Here is how I save it with NSUserDefaults : var defaults = NSUserDefaults.standardUserDefaults() defaults.setObject(downloadedFile as NSMutableArray, forKey: "myKey") And here how I retrieve it: var downloadedFilesFromUserDefaults:NSMutableArray = defaults.objectForKey("myKey") as NSMutableArray 回答1: take look at this and try to save you array like this! as this worked perfectly! var arr:NSMutableArray = NSMutableArray(objects: "ASD","aSd") NSUserDefaults

Do I have to create some dummy hardcoded array with data for viewing prefs in table view?

筅森魡賤 提交于 2020-01-06 11:45:33
问题 How to create a UITableViewController that displays some hardcoded data in grouped styled (like iPhone settings). For example I need to show some menu options in a table with group style. Now, I know to work with tables and have done it already. But I'm not sure about how should I deal with data that table view will read for constructing the table. Those rows just present some menu options like "order", "review", "about us" then IMHO I have to create some array with that data and store in

Save an object in NSUserDefaults and Realm

点点圈 提交于 2020-01-06 07:19:14
问题 Is it possible to save an object in both NSUserDefaults and Realm (Swift) ? I have found a problem in creating my Model since NSUserDefaults require the inheritance of NSObject and Realm requires the inheritance of Object . Doing so , raised this error Multiple inheritance from classes 'Object' and 'NSObject' 回答1: Using Swift4's Codable protocol, you can save a custom class to UserDefaults without having to conform to the old NSCoding protocol. class Team: Object, Codable { @objc dynamic var

How to decode data of an array that is save and read from userDeafults - Swift

泪湿孤枕 提交于 2020-01-06 02:45:14
问题 I am working on a project that it has a plist contains of rows of dictionaries , and then , I put all the rows of datas to an array and I save it to the useDefaults and all these things seems correct , but in the read method , I understand that my data seems to be coded and it shows it in codes. like this (6b756e74) I wonder to know how I can decode my data in a very correct way. here is my codes struct Country : Codable { let orFlagEmoji, destFlagEmoji : String private enum CointryKeys :

Saving NSMutableArray to NSUserDefaults

做~自己de王妃 提交于 2020-01-06 01:35:12
问题 I have an NSMutableArray inside of my AppDelegate , and I'm attempting to save it to NSUserDefaults . The NSMutableArray (strainsfinal) contains a list of favorited items. I want this list to save, and be present even if the app is shut down, and then restarted. Does anyone know why my code isn't working (not saving my data)? See below: AppDelegate.m -(void)updateStrains:(NSDictionary *)item { NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults]; NSData *dataSave =