nsuserdefaults

NSUserDefaults to present window only on first launch

房东的猫 提交于 2019-12-11 08:50:11
问题 i am trying to get a window to show (which it successfully does) on first launch, there is a button on that window (for testing purposes) that sets the bool firstLaunch = NO. for some reason, after pressing the button, the view is not dismissed. app delegate userDefaults = [NSUserDefaults standardUserDefaults]; [userDefaults setBool:firstLaunch forKey:@"firstLaunch"]; newViewController = [[NewView alloc]init]; newViewController.appDelegateOutlet = self; [userDefaults synchronize]; if (

custom object with CCSprite that conforms to NSCoding not displaying

喜欢而已 提交于 2019-12-11 08:01:56
问题 In my effort to save a ScrollingBackground object I've subclassed the CCSprites to conform to NSCoding. The ScrollingBackground doesn't display. Please see the relevant code below. I'm not really sure whats wrong. Please help. ScrollingBackground.h: (CCBackgroundSprite's interface) @interface CCBackgroundSprite: NSObject <NSCoding> @property (nonatomic, assign) float xValue; @property (nonatomic, assign) float yValue; @property (nonatomic, retain) NSString* backgroundStringName; @end

How to apply NSCoding to a class?

孤者浪人 提交于 2019-12-11 08:00:01
问题 I have the following class. When I try to add it to NSUserDefaults like this: let testClass = TestClass() testClass.Property1 = 22.3 NSUserDefaults.standardUserDefaults().setObject(testClass, forKey: "object1") I get an error: 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object for key object1' class TestClass: NSObject, NSCoding { var Property1:Double? override init() { super.init() } required init?(coder aDecoder: NSCoder) { if let priceCoded = aDecoder

Save the select state of a button in UITableView row (Swift)

烈酒焚心 提交于 2019-12-11 07:32:17
问题 I have a button called btnChk2 on a UITableview row. When the user press the btnChk2 that the button btnChk get selected. The code above works to make that happen but when I quit the app and open it back up the status of the checkbox is the not the same, what I want for example is that if a row checkbox is selected, I want when the user leaves the app and comeback the same checkbox stay selected, tried it with NSUserDefaults but didn't worked with me. Here is the code that works but it doesn

adding user defaults to dark mode

北战南征 提交于 2019-12-11 07:25:45
问题 This is a continuation of an earlier post. What I was wondering was how to add the user defaults for the dark mode throughout the app. Please do not pay attention for the code that says UserDefaults in my last post, I was following a tutorial and just kind of copied what he did, not knowing anything at all about User Defaults. The whole dark mode works beautifully throughout the app. I just need to know how to do all the user defaults. If you have any questions feel free to ask. The code

STRUCT Array To UserDefaults

狂风中的少年 提交于 2019-12-11 07:13:56
问题 I have a custom Struct class to hold calories, fats, carbs, and protein. Each Time a user enters the data I put it into a variable var theArray : NSMutableArray = [] struct CFCPstruct { let calories : Int! let fats : Int! let carbs : Int! let protein: Int! init(Calories: Int, Fats: Int, Carbs: Int, Protein: Int) { self.calories = Calories self.fats = Fats self.carbs = Carbs self.protein = Protein } } let addLog = [CFCPstruct(Calories: totalCalories, Fats: totalFats, Carbs: totalCarbs, Protein

Is it possible to save the state of a timer in the User Defaults?

此生再无相见时 提交于 2019-12-11 07:06:49
问题 I have a label on which I am showing countdown timer. Now if I close my app the timer will be off and the label's text also. I know that we can save the label's text value. But how do we show the correct countdown when the app starts again. Suppose I close at 00:05:35 after 3 minutes when app is launched again the label should show 00:02:35 and the timer should be there for remaining countdown 回答1: Yes, simply store the time at which your app was closed and the time left to count down in

NSUserdefaults works on Simulator but not on Device

人盡茶涼 提交于 2019-12-11 06:45:11
问题 I would like to save an NSArray to NSUSerDefaults . If I do it on Simulator everything works, if I do it on Device, it doesnt work. NSArray *Test1 = [Daten copy]; NSArray *Test2 = [Kosten copy]; [prefs setObject:Test1 forKey:@"Daten"]; [prefs setObject:Test2 forKey:@"Kosten"]; I am using the above code. prefs is a normal NSUserDefaults , like NSUserDefaults *prefs = [NSUserDefaults standartUserDefaults]; ... Daten & Kosten are Mutable Arrays, to work with. Everything works on simulator, but

User Defaults not saving dictionary contents in swift 3

邮差的信 提交于 2019-12-11 06:08:10
问题 I am trying to add a key and a value to a dictionary then add this dictionary the user defaults and read back into a dictionary object. I have two questions that I would really appreciate any help in, 1) why is the dictionary being read from user defaults empty? Since I added a key and a value to the dictionary shouldn't those be saved to the dictionary I retrieve from user defaults? let defaults = UserDefaults.standard; var myDict = [String: String]() myDict["key"] = "value" defaults

Save NSMutableArray in NSUserDefaults

怎甘沉沦 提交于 2019-12-11 05:53:14
问题 I need to save a NSMutableArray to NSUserDefaults . I have tried this, but the load method returns a nil NSMutableArray : // NSMutableArray *listaAenviar = [[NSMutableArray alloc]init]; -(void) saveArray { NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults]; [_listaAenviar addObject:@"1"]; [currentDefaults setObject:[NSKeyedArchiver archivedDataWithRootObject:[_listaAenviar mutableCopy]] forKey:@"listaAenviar"]; [currentDefaults synchronize]; } -(void) loadArray {