nsuserdefaults

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

蹲街弑〆低调 提交于 2019-12-20 03:43:21
问题 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

Swift optionals - warning on conditional cast from 'x' to 'x' always succeeds

回眸只為那壹抹淺笑 提交于 2019-12-20 02:45:19
问题 I was wondering if there is a way to turn off/avoid 'yellow' warnings in xcode on if let...NSUserDefaults constructs where the key is of a known value. For example: if let x = NSUserDefaults.standardUserDefaults().integerForKey("myKey") as? Int {...} Because of the if let I have to use as? . However, as I am using a known value type (in this case integer) the as? Int is effectively redundant - which is why I am getting the 'yellow warning'. Thoughts? Is there a better way to code these types

Updating & changing settings plist files with new versions of an app

旧巷老猫 提交于 2019-12-20 02:13:44
问题 I've got a default settings plist file in the resources folder of my app, and on the first launch that gets copied to the documents folder. In successive versions of the app, how can I merge the plist settings in their documents with any new keys & values (possibly nested) that have been added since the previous version? I've seen a pattern where properties are actually created as an NSDictionary in the app (with all default settings), and then the current settings saved in the plist file is

Tell The Program What To Do When No Save Data Is Found NSUserDefaults, iPhone

元气小坏坏 提交于 2019-12-19 11:52:14
问题 I have saved data which was saved using NSUserDefaults. I was under the impression that if there was nothing saved to the key already (first time app is run) it would default to 0. This however doesn't seem to be the case. Here is what I have: To save: - (void)viewWillDisappear:(BOOL)animated { [[NSUserDefaults standardUserDefaults] setInteger:setbatteryHealthCalculated forKey:@"healthValue"]; [[NSUserDefaults standardUserDefaults] synchronize]; } To load: - (void) viewWillAppear:(BOOL

what is the best way for saving username and High Score

丶灬走出姿态 提交于 2019-12-19 11:35:47
问题 In my app I need to save a double value (high score) and String (player name) what should i use to get this. any idea will be great. Thank you 回答1: As deanWombourne said, you can use NSUserDefaults to store these data but it isn't very secure. If you don't want to store this data "in the air", you can take a look to SFHFKeychainUtils by Buzz Andersen to store them in the iPhone Keychain. First of all, copy SFHFKeychainUtils files to your project. Click on the SFHFKeychainUtils.m and click on

how can store custom objects in NSUserDefaults

我怕爱的太早我们不能终老 提交于 2019-12-19 09:55:42
问题 I apologize for duplicate Question . I am new in ios . I want to store custom objects in userdefaults. I am using objective-c . Thanks in advance 回答1: First you create custom class Like below. CustomObject.h #import <Foundation/Foundation.h> @interface CustomObject : NSObject<NSCoding> @property(strong,nonatomic)NSString *name; @end CustomObject.m #import "CustomObject.h" @implementation CustomObject - (void)encodeWithCoder:(NSCoder *)encoder { //Encode properties, other class variables, etc

Need to archive CLLocation data

丶灬走出姿态 提交于 2019-12-19 07:56:13
问题 I have an array of CLLocation data that I would like to archive. Should the NSUserDefaults system be used? Otherwise, how best to archive the CLLocation data? 回答1: UserDefaults can only store certain types of data, and should be used to store user preference information, not arbitrary application state data. To quote the Apple docs: The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an application to customize its

Data persistence through NSUserDefaults

北城以北 提交于 2019-12-19 04:19:07
问题 Is data persisted in NSUserDefaults between app launches? I want some small data to be persisted even if I quit and relaunch the app. 回答1: Yes. Data will persist in NSUserDefaults for the entire lifetime of the app. 回答2: Data will persist. But, NSUserDefaults is used primarily for preferences. Users expect that it is okay to delete the preference file without affecting their documents and created data. If the data is not a preference, you may want to store the data in a file inside ~/Library

Xcode iOS: check if user is logged in and show different views if not

拥有回忆 提交于 2019-12-19 04:07:12
问题 I'm coding an app where a logged in user has got a couple of extra functionalities than a non logged in user. Basically, I have more or less 5 tabs. When I launch the app, the user immediately gets the login page. He can decide to skip it. If he skips it, there'll only be 3 tabs for him. If he logs in successfully, there'll be 5. I already have my login page made. I just don't know how I can store a session if the user is logged in correctly, and only display a certain number of tabs if the

Reading NSUserDefaults in watchOS 2 (I know App Groups doesn't work)

。_饼干妹妹 提交于 2019-12-19 03:20:11
问题 Apple documentation says "Also, iOS automatically forwards a read-only copy of your iOS app’s preferences to Apple Watch. Your WatchKit extension can read those preferences using an NSUserDefaults object..." . https://developer.apple.com/library/prerelease/watchos/documentation/General/Conceptual/WatchKitProgrammingGuide/SharingData.html#//apple_ref/doc/uid/TP40014969-CH29-SW1 But I can't read defaults in my WatchKit app that were saved in my iPhone app, am I doing something wrong? In the