nsuserdefaults

iOS: How to “Refresh” a UIViewController after Popping its Child UIViewController?

风流意气都作罢 提交于 2019-12-09 21:32:44
问题 In my app I'm using UINavigationController. I have a "parent" UIViewController and a "child" UIViewController running on the stack. The user can do some settings on the child that are later on suppose to affect the parent. I use NSUserDefaults to save and retrieve the data, and it seems to be working fine according to the NSLog. What I'm not clear about is how am I supposed to "refresh" the data once I come back from the child. Let me be more specific: In the child there is a "Back" button

Save Session Data in iPhone

♀尐吖头ヾ 提交于 2019-12-09 19:44:53
问题 I want to store data at different points in my app, that is accessible to objects across the app. Something similar to session in php or global variables. I know I can use NSUserDefaults but i am not sure how i would keep on adding values to it and then accessing it. Example, first i want to store the Username that is used during login, then on 3rd screen, i want to save the Company of that user that he selects from a list of companies. Then on the 5th screen i want to save the location that

Having problems reading settings while using InAppSettingsKit

橙三吉。 提交于 2019-12-09 13:34:55
问题 I am using the InAppSettingsKit modules to manage my settings. I can include it in my project to the point where I can build a settings page that interacts correctly with my project. I have a root.plist that I can change and when I first run my app on the simulator I can see the changes reflected. However, for the life of me, I cannot access the settings in NSUserDefaults through my code. When I run the code below I can loop through the contents of the [NSUserDefaults standardUserDefaults] .

Setting Up HighScore in Swift and Sprite Kit using NSuserdefaults

我与影子孤独终老i 提交于 2019-12-09 04:57:14
问题 I am building a swift game and a need to set up a highscore , i have been trying to figure out how to do it for a while. So please can you tell me how to search this library to see if there is a already saved high score and then compare it to the user's score. I have tried coming out with this but it won't work. Please Help and be as clear as possible. Giving me example code would be extremely appreciated. if let highscore: AnyObject = NSUserDefaults.valueForKey("highscore") { var savedScore:

IOS: store an array with NSUserDefault

别说谁变了你拦得住时间么 提交于 2019-12-09 04:57:04
问题 I want to store an array with NSUserDefault , then, I put in applicationDidEnterBackground [[NSUserDefaults standardUserDefaults] setObject:myArray forKey:@"myArray"]; and in application didFinishLaunchingWithOption myArray= [[NSMutableArray alloc] initWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"myArray"]]; it's ok for multitasking device, but for not-multitasking device, how can I solve? 回答1: Store the object in NSUserDefaults in -applicationWillTerminate: , if it hasn't

Save a tuple in NSUserDefaults

一曲冷凌霜 提交于 2019-12-09 03:11:49
问题 I'm using a tuple to store something like this. var accessLavels: (hasInventoryAccess: Bool, hasPayrolAccess: Bool) accessLavels = (hasInventoryAccess: true, hasPayrolAccess: false) Now I want to save it in NSUserDefaults . NSUserDefaults.standardUserDefaults().setValue(accessLavels, forKey: "AccessLevelKey") NSUserDefaults.standardUserDefaults().synchronize() But I get the following error. Type '(hasInventoryAccess: Bool, hasPayrolAccess: Bool)' does not conform to protocol 'AnyObject' How

NSMutableDictionary: mutating method sent to immutable object

倖福魔咒の 提交于 2019-12-09 02:26:51
问题 The following code is returning an exception with the following error message "mutating method sent to immutable object" when attempting to removeObjectForKey NSMutableDictionary * storedIpDictionary = (NSMutableDictionary*)[[NSUserDefaults standardUserDefaults] dictionaryForKey:@"dictDeviceIp"]; NSString *key = self.currentDeviceNameText.text; NSString *ipAddressTemp = [storedIpDictionary objectForKey:key]; [storedIpDictionary removeObjectForKey:key]; <----Crashes here storedIpDictionary[key

How to deal with non-optional values in NSUserDefaults in Swift

僤鯓⒐⒋嵵緔 提交于 2019-12-08 20:58:34
To get a value from NSUserDefaults I would do something like this: let userDefaults = NSUserDefaults.standardUserDefaults() if let value = userDefaults.objectForKey(key) { print(value) } However, these methods do not return optionals: boolForKey (defaults to false if not set) integerForKey (defaults to 0 if not set) floatForKey (defaults to 0.0 if not set) doubleForKey (defaults to 0.0 if not set) In my app I want to used the saved value of an integer if it has been previously set. And if it wasn't previously set, I want to use my own default value. The problem is that 0 is a valid integer

How to know if window is minimizable when titlebar was double clicked?

梦想的初衷 提交于 2019-12-08 17:24:32
问题 This image is from SystemPreferences > Appearance I want to know How do I get that value programmatically? I ask because I am drawing a window with a customized titlebar and I want it to resemble (in behavior) as much as possible to normal (non-customized) cocoa windows. Maybe a terminal command I can pipe or is there an cocoa API that does this? EDIT: Answer (thanks to NSGod) - (void)mouseUp:(NSEvent *)event{ if ([event clickCount] == 2) { //Get settings from "System Preferences" >

Can other programs read my NSUserDefaults settings?

自古美人都是妖i 提交于 2019-12-08 15:45:11
问题 On the iPhone, not including jail-broken phones, can other apps read the values you've set using NSUserDefaults ? I'm considering saving the customer's userid/password for our service and want to make sure it is secure. 回答1: No, other applications cannot see your data. That said, you should probably consider using the keychain on the iPhone to store sensitive data like usernames and passwords. 回答2: No, applications are sandboxed. This includes their own directory for preferences and user data