nsuserdefaults

Need to archive CLLocation data

梦想的初衷 提交于 2019-12-01 05:47:05
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? 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 behavior to match a user’s preferences. For example, you can allow users to determine what units of

Error when trying to save to NSUserdefaults

ぐ巨炮叔叔 提交于 2019-12-01 05:43:28
问题 I have a table which works in the following way. If a row is selected, an amount corresponding to the selected row is added to var total , a checkmark is added. If it is deselected, the amount will be subtracted, the checkmark will be set to none. My code worked properly before trying to save/retrieve the data to/from NSUserDefaults. The errors are: when I select the first row, it subtracts the amount instead of adding it; after a row is selected, if I tap on the back button and then come

iOS开发中常用的单例

社会主义新天地 提交于 2019-12-01 05:30:45
1、UIApplication(应用程序实例) 获取方式:[UIApplication sharedApplication] 详细:http://www.cnblogs.com/hissia/p/5678518.html 2、NSNotificationCenter(消息中心) 获取方式:[NSNotificationCenter defaultCenter] 常用的通知模式 3、NSFileManager(文件管理) 获取方式:[NSFileManager defaultManager] 4、NSUserDefaults(偏好设置) 获取方式:[NSUserDefaults standardUserDefaults] 详细:http://www.cnblogs.com/hissia/p/5642405.html 5、NSURLCache(请求缓存) 获取方式:[NSURLCache sharedURLCache] 6、NSHTTPCookieStorage(应用程序cookies池) 获取方式:[NSHTTPCookieStorage sharedHTTPCookieStorage] 7、NSURLSession(发送请求时候用的) 获取方式:[NSURLSession sharedSession] 8、UIMenuController(弹出的 菜单 可以选择,复制,剪切

NSUserDefaults not saving

a 夏天 提交于 2019-12-01 04:51:23
I am having a problem in my sprite kit app where my NSUserDefaults variable is not working. In createSceneContents (which I know is being called) if (![defaults objectForKey:@"obj"]) { difficultyLabel.text = @"Difficulty: Easy"; [defaults setObject:@"Easy" forKey:@"obj"]; } else { difficultyLabel.text = [NSString stringWithFormat:@"Difficulty: %@", [defaults objectForKey:@"diff"]]; } and then when you click on the SKLabelNode to change the difficulty and this code is being called if ([label.text isEqualToString:@"Difficulty: Easy"]) { label.text = @"Difficulty: Hard"; [defaults setObject:@

force reset NSUserDefault on iPhone App upgrade

纵然是瞬间 提交于 2019-12-01 04:34:03
问题 i want to force reset to NSUserDefault whenever user update my app. why i need this because every update include some new information abt user. as some info (token) already present in NSUserDefault my app does not call to my web service. due to that fact i dont have new user info. and also i dont want to write if..else statement for every new release. thanks so much. hope my question is pretty clear. 回答1: Check this out: [NSUserDefaults resetStandardUserDefaults] For more info check the

Save a tuple in NSUserDefaults

末鹿安然 提交于 2019-12-01 04:24:33
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 can I resolve this issue? If its impossible, then any other suggestions to save a tuple is welcome.

How to use NSUbiquitousKeyValueStore and NSUserDefaults together

微笑、不失礼 提交于 2019-12-01 03:55:42
Documentation is not clear on how to use NSUbiquitousKeyValueStore with edge cases. If I want to set a value, I understand that I should set a value to both NSUserDefaults and NSUbiquitousKeyValueStore since iCloud could be disabled. However in my tests [NSUbiquitousKeyValueStore defaultStore] return a valid object even if iCloud is disabled (tested on Mac OS). Also, to my understanding is that if iCloud is enabled, NSUbiquitousKeyValueStore 's values are stored to disk (and available offline). What are the reason to use NSUserDefaults if you are sure that you have less than 64KB of data? I am

How to save struct to NSUserDefaults in Swift 2.0

ぃ、小莉子 提交于 2019-12-01 02:01:00
I have a struct named Jar and I would like to save an array of them to NSUserDefaults. Here is the jar struct code: struct Jar { let name: String let amount: Int init(name: String, amount: Int){ self.name = name self.amount = amount } } I belive that I will need to convert this to an NSObject to be able to save it. (Because you can't save a struct directly to NSUserDefaults). My questions are: How do I convert an array of structs to an NSObject? and How to convert an NSObject back at an array of structs. This solution is inspired by @Duncan C. I wrote it more familiar way as we do in case

Data persistence through NSUserDefaults

回眸只為那壹抹淺笑 提交于 2019-12-01 00:46:42
Is data persisted in NSUserDefaults between app launches? I want some small data to be persisted even if I quit and relaunch the app. Yes. Data will persist in NSUserDefaults for the entire lifetime of the app. 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/Application Support/[your application's name]/ instead. 来源: https://stackoverflow.com/questions/4771496/data

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

笑着哭i 提交于 2019-11-30 23:59:31
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 user isn't. I come from PHP, I've just started learning Objective-C, so I'm looking for the same thing