nsuserdefaults

NSUserDefaults: What's the +resetStandardUserDefaults method good for? How can I provide “system settings”?

大憨熊 提交于 2019-12-11 01:18:06
问题 I want the user to be able to make some preferences like colors, prefered images, etc. When I use NSUserDefaults for this, on first start of the app there will be no preferences, right? So, every time I want to get a preference like NSInteger avatarID = (NSInteger)[[NSUserDefaults standardUserDefaults] objectForKey:@"avatar"]; I have to check if it's null, and then use my system preference. But then I've seen this in the docs: +resetStandardUserDefaults Are there two branches of defaults

How to check a single time if UserDefaults is empty

风流意气都作罢 提交于 2019-12-10 23:00:00
问题 My app counts the days between a date and NSDate(). When I released it, a user could only save one date, a title and a background image. Now I have a UICollectionView with the option to save more than one date, and it will create a cell by appending a date, title and image string to their respective arrays. The app has been completely changed, so I'm struggling with how to check whether a user has saved a date, and if they have, add that info to the arrays to create a cell. But, I want this

iOS NSDictionary saved to NSUserDefaults not saving values

谁说胖子不能爱 提交于 2019-12-10 20:47:47
问题 I am trying to save a NSDictionary with array values to NSUserDefaults but am having some strange trouble. My NSDictionary has NSStrings for keys and each value is a NSArray of NSNumbers . When I print the dictionary out, everything is fine. I write this dictionary to NSUserDefaults and if I read it back out right away, everything seams fine. Using this everything seams just fine: [[NSUserDefaults standardUserDefaults] setObject:self.selectedOptionPositions forKey:PREF_OPTIONS_KEY]; [

How to implement NSUserDefault to access through multiple views

百般思念 提交于 2019-12-10 20:18:27
问题 I'm trying to share strings and integers throughout multiple views for a final project in an introductory iOS development course, around 50, and am wondering how I would go about doing this... I know the MVC paradigm is best but we didn't get to very advanced stuff, especially core data. I was thinking of using NSUserDefaults, I know it's wrong but this app doesn't have to be blazingly fast, and I think this would be the simplest way for me. My question is, where and how would I declare the

Retrieving String Value from User Defaults in Swift 3

谁说我不能喝 提交于 2019-12-10 18:48:03
问题 I have a method that sets a String value in UserDefaults , but when I try to retrieve the value in a print statement, I get nil . Can anyone see what I am doing incorrectly? static func setPreferredUnitsOfMeasurementSystem(_ system: UnitsOfMeasurementSystem) { // system.rawValue is of type String UserDefaults.standard().set(system.rawValue, forKey: unitsOfMeasurementSystemKey) print(UserDefaults.standard().string(forKey: unitsOfMeasurementSystemKey)) } 回答1: I just ran into the same issue.

Error when trying to save indexPath to NSUserDefaults

十年热恋 提交于 2019-12-10 18:21:54
问题 I am trying to save the indexPath for UICollectionView, but I get the following error: libc++abi.dylib: terminating with uncaught exception of type NSException My code is: Save index path: [[NSUserDefaults standardUserDefaults] setObject:indexPath forKey:@"CollectionIndex"]; [[NSUserDefaults standardUserDefaults] synchronize]; Load indexPath: NSIndexPath *storedIndexPath = [[NSUserDefaults standardUserDefaults] objectForKey:@"CollectionIndex"]; I have commented out code to find out which code

MKPolyline -> NSKeyedArchiver -> NSData SIGABRT

梦想的初衷 提交于 2019-12-10 15:19:29
问题 In my app I am trying to store an array of MKPolylines into NSUserDefaults . NSData *data = [NSKeyedArchiver archivedDataWithRootObject:overlays]; [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"theKey"]; Gives: [MKPolyline encodeWithCoder:]: unrecognized selector sent to instance 0x169c20` Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [MKPolyline encodeWithCoder:]: unrecognized selector sent to instance 0x1c57e0' Edit: I made some progress.

Converting NSUserDefaults to Keychain?

蓝咒 提交于 2019-12-10 14:50:15
问题 So, NSUserDefaults is quite easy to use. But apparently, it is not too secure - there is no encryption. And of course the client wants the app prefs to be secure because it contains sensitive data. But the Keychain is secure, though hard to code (apparently). So is there a way to easily convert NSUserDefaults code to Keychain code? In other words, I want to store app prefs within the Keychain. Or am I barking up the wrong tree? 回答1: Both of the below solutions are wrappers around KeyChain API

-[_SwiftValue encodeWithCoder:]: unrecognized selector sent to instance

荒凉一梦 提交于 2019-12-10 12:45:30
问题 Getting error when trying to utilize NSCoder Player.swift: class Player: NSObject, NSCoding { private var _playerName: String! private var _playerScore: Int! private var _playerColor: PlayerColor! //PlayerColor is an enum var playerName: String { get { return _playerName } set { _playerName = newValue } } var playerScore: Int { get { return _playerScore } set { _playerScore = newValue } } var playerColor: PlayerColor { get { return _playerColor } set { _playerColor = newValue } } init

Approaching App Release: 2 Quick Questions

北战南征 提交于 2019-12-10 12:03:58
问题 as I get closer to releasing my app, I'm trying to make sure that I'm using stable code to check if the app has been launched before (in order to perform some first time setup). Is this (obviously a no frills method that doesn't take into account app version and updates) pretty much a rock solid way to determine if the app has been launched? In my app delegate didFinishLaunchingWithOptions method, I perform the following each time: NSUserDefaults *defaults =[NSUserDefaults