nsuserdefaults

Saving an image array with UserDefaults

隐身守侯 提交于 2019-12-17 20:52:13
问题 I have an app where the user takes a picture and once the picture is taken it should be saved to UserDefaults . I keep getting this error: "cannot invoke 'setObject' with an argument list of type '(UIImage. type, forKey:[UIImage])'" I've searched through documentation and posts on here, but nothing helps. This is my code. let defaults = NSUserDefaults.standardUserDefaults() func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject])

Error when trying to save image in NSUserDefaults using Swift

混江龙づ霸主 提交于 2019-12-17 19:25:53
问题 When i try to save an image in NSUserDefaults, the app crashed with this error. Why? Is it possible to save an image with NSUserDefaults? If not, then how do I save the image? Image... Code... var image1:UIImage = image1 var save1: NSUserDefaults = NSUserDefaults.standardUserDefaults() save1.setObject(Info.Image1, forKey: "Image1") save1.synchronize() Log error... libc++abi.dylib: terminating with uncaught exception of type NSException (lldb) 回答1: NSUserDefaults isn't just a big truck you can

NSUserDefaultsDidChangeNotification and Today Extensions

China☆狼群 提交于 2019-12-17 18:33:07
问题 I am developing an iPhone app with a Today Extension . The app has a Model module that loads from/saves to NSUserDefaults . Since I want this information to be available to both the main app and the extension, I use an app group: let storage = NSUserDefaults(suiteName: "group.etc.etc.etc...") Both the app and the extension can access the information without any problem. The main app occasionally might create a local notification to present to the user. That notification has two actions

Passing Data from App delegate to View Controller

喜你入骨 提交于 2019-12-17 18:22:14
问题 I need to Pass an string from App delegate to my Initial View Controller , Can somebody listed me the best way to do it , also i tried to Save and Retrieve using NS user Defaults, but i doesn't work out properly . 回答1: Interface: @interface MyAppDelegate : NSObject { NSString *myString; } @property (nonatomic, retain) NSString *myString; ... @end and in the .m file for the App Delegate you would write: @implementation MyAppDelegate @synthesize myString; myString = some string; @end Then, in

How to retrieve values from settings.bundle in objective c?

北慕城南 提交于 2019-12-17 17:57:26
问题 I have created a project that set and retrieve values from settings.bundle . I have also set some defaults values in settings.bundle file. Now the problem is when I retrieve values as NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; loginName.text = [defaults objectForKey:@"login_name"]; for the first time it shows null, but the values get set in iPhone application settings. If I change the values or set it manually, then values are retrieved properly. Help me out 回答1:

NSUserDefaults Unreliable in iOS 8

牧云@^-^@ 提交于 2019-12-17 17:33:28
问题 I have an app that uses [NSUserDefaults standardUserDefaults] to store session information. Generally, this information is checked on app launch, and updated on app exit. I have found that it seems to be working unreliably in iOS 8. I am currently testing on an iPad 2, although I can test on other devices if need be. Some of the time, data written before exit will not persist on app launch. Equally, keys removed before exit sometimes appear to exist after launch. I've written the following

How to store user data iOS

人走茶凉 提交于 2019-12-17 16:31:22
问题 I need to store data that the user can add, they can add an unlimited amount. They can either be NSStrings or UIImage s. I have looked into NSUserDefaults but it seems that it is used for small amounts of data such as settings or preferences. What would be the best/most secure way to store the users information so that when they close the app it is still in the app. The data populates a UITableView and is a NSMutableArray . Whats the best way to do this? 回答1: You should use Core Data. There

NSUserDefaults not cleared after app uninstall on simulator

。_饼干妹妹 提交于 2019-12-17 06:34:20
问题 this may sound real NOOB! I want to check if it's the second time the user enters my application, so to keep the run count I'm using NSUserDefaults . I have implemented the following code in my rootViewController 's viewDidLoad method: NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSLog(@"hello %ld", (long)[userDefaults integerForKey:@"runCount"]); if ([userDefaults integerForKey:@"runCount"] != 1) { //not the 2nd run [userDefaults setInteger:1 forKey:@"runCount"];

Delete all keys from a NSUserDefaults dictionary iOS

拥有回忆 提交于 2019-12-17 06:29:53
问题 I use the NSUserDefaults dictionary to store basic information such as high scores etc so that when the user closes the app data is not lost. Anyways I use: NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; to store data. If I wish to store a new high score for example then I would do: [prefs setInteger:1023 forKey:@"highScore"]; [prefs synchronize]; //this is needed in case the app is closed. and later if I wish to retrieve the high score I would do: [prefs integerForKey:@

What is the use of -[NSUserDefaults registerDefaults:]?

自作多情 提交于 2019-12-17 04:29:03
问题 What is the difference between: [[NSUserDefaults standardUserDefaults] registerDefaults: [NSDictionary dictionaryWithObjectAndKey:anObject, @"something"]]; And this: [[NSUserDefaults standardUserDefaults] setObject:anObject forKey:@"something"]; 回答1: The difference is that the first code-snippet you register defaults that will be used when the user has not made any changes to the "property". So if you want to provide let's say a "property" with the key name 'Welcome message', you could