nsuserdefaults

iPhone: preserve NSUserDefaults values when application is killed

ε祈祈猫儿з 提交于 2019-12-02 13:40:01
问题 I am trying to implement "Add to Favorites" functionality using NSUserDefaults. So far I have written following code. - (void)favouriteButtonClicked:(id)sender { favselected = !favselected; // favselected is BOOL property MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; NSString* viewname = @"custom"; if(favselected) { [favButton setBackgroundImage:[UIImage imageNamed:@"selected.png"] forState:UIControlStateNormal]; [appDelegate addTOFavourites:self

Storing NSMutableArray filled with custom objects in NSUserDefaults - crash

六月ゝ 毕业季﹏ 提交于 2019-12-02 13:38:36
EDIT: Here is a working version. I was able to retrieve my object within the NSMUtableArray after I saved and loaded it from the NSUserDefaults via NSCoding. I think it's important to mention, that you not only need to de-archive the array, but also all its content. As you can see, I had to not only store the NSData of my freeze object, but also the NSData of my array: // My class "Freeze" @interface Freeze : NSObject <NSCoding> // The NSCoding-protocoll is important!! { NSMutableString *name; } @property(nonatomic, copy) NSMutableString *name; -(void) InitString; @end @implementation Freeze

Save UIImage array in NSUserDefaults

大兔子大兔子 提交于 2019-12-02 13:38:09
I want to put a UIImage array into UserDefaults and then retrieve it. After that set the retrieved images in an image view. How can I do that? You can easily save your image in documentDirectory as below: let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first let fileURL = documentDirectory?.appendingPathComponent(yourImageName) and then, you can give your image to UserDefaults Tejas Ardeshna First of all that is not ideal way to save image in user default but if you want you can do following things Save let imageData = NSKeyedArchiver.archivedData

Pass data from one ViewController to another ViewController using NSUserdefaults

我怕爱的太早我们不能终老 提交于 2019-12-02 13:35:45
I need to data from one ViewController to another ViewController Here I've Multiple Textfields in first ViewController then it will passed the SecondViewController in Whatever Data i entered in FirstViewController. Can You Please suggest me. this is for storing NSString *verifyStatus=@"Y"; [[NSUserDefaults standardUserDefaults]setObject:verifyStatus forKey:@"verify_status"]; [[NSUserDefaults standardUserDefaults] synchronize]; for retrieving NSString *verify_status = [[NSUserDefaults standardUserDefaults]stringForKey:@"verify_status"]; You can also use property for this... Because It's easy ..

iPhone inputting NSUserDefaults into a UITextField

浪子不回头ぞ 提交于 2019-12-02 13:19:49
问题 I am writing a program where I where the first time a user runs it - they will have to fill out about 10 different UITextFields. I am trying to save the fields so that on subsequent runs of the program that whatever they previously put will already be displayed in those UITextFields so the wont have to re-input it in - unless they want to edit something in which case they still have that option. I think that I have figured out a good way to save the strings using NSUserDefaults but now I am

iPhone's NSUserdefaults is a database or plist

给你一囗甜甜゛ 提交于 2019-12-02 12:40:23
问题 I am not able to get NSUserDefaults concepts properly. Is that a database of plist file ? 回答1: It's a key-value store that is persisted between restarts of your application. How it's implemented has little bearing on how you use it. 回答2: I don't know if it's different on the iPhone OS (which i don't believe) but in Mac OS X is it a plist file in your Library/Preferences folder. Pretty sure it's the same on iPhone OS/iOS 来源: https://stackoverflow.com/questions/3178115/iphones-nsuserdefaults-is

Using NSUserDefaults for storing UISwitch state

北慕城南 提交于 2019-12-02 11:42:14
问题 I am trying to persist the UISwitch state in my settings view of my application. Basically it is a UITableView and contains a few switches to get the user preferences. The below code explains how the switches are constructed (only one switch construct is given below, others are also constructed the sameway). if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SomeIdentifierB] autorelease]; if (syncStartupSwitch) { syncSwitch.on = YES; }else {

How to set Dictionary in NSUserDefault in swift?

房东的猫 提交于 2019-12-02 08:16:30
问题 I've a mutable dictionary (in form of [Int:Int]) and want that to save it. I would use NSUserDefaults like that: var myDic: NSMutableDictionary = [:] myDic = [1:2] NSUserDefaults.standardUserDefaults().setObject(myDic, forKey: "myDic") but with that I get an error: Thread 1: signal SIGABRT I have no idea why. 回答1: setObject(_:forKey:) can’t accept Dictionary with a key which is integer type. The method requires property-list objects, but myDic = [1:2] is not property-list object. There are

How to use NSUserDefaults to store an array of dictionaries

走远了吗. 提交于 2019-12-02 08:03:29
Trying to store an array of dictionaries with NSUserDefaults . var theTasks: [[String:Any]] = [["num":1,"title":"example","colour":"red"]] let defaults = NSUserDefaults.standardUserDefaults() defaults.setObject(theTasks, forKey: "myTasks") defaults.synchronize() let selected = theTasks[1] Gives error: Cannot convert value of type '[[String:Any]]' to expected argument of type 'AnyObject?' Swift 3.x In Swift 3 it has changed so now it needs to be saved as [Any] Any Array and use UserDefaults array(forKey:) method to load it: let theTasks: [Any] = [["num": 1, "title": "example", "colour": "red"]]

NSUserDefaults Settings Bundle Plist

女生的网名这么多〃 提交于 2019-12-02 05:42:41
I have an app that checks for a file upon load from the appDelegate's appDidFinishLoading method using a url value that I supposedly store in the NSUserDefaults Settings Root Plist: NSString *pathStr = [[NSBundle mainBundle] bundlePath]; NSString *settingsBundlePath = [pathStr stringByAppendingPathComponent:@"Settings.bundle"]; NSString *finalPath = [settingsBundlePath stringByAppendingPathComponent:@"Root.plist"]; NSDictionary *settingsDict = [NSDictionary dictionaryWithContentsOfFile:finalPath]; NSArray *prefSpecifierArray = [settingsDict objectForKey:@"PreferenceSpecifiers"]; NSDictionary