Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • NSUserDefaults

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 324
    Comment on it

    NSUserDefaults is used to save the data until the app is installed. When data to NSUserDefaults is written by you then it will automatically gets loaded when your app runs so that you can read it back again.

    In NSUserDefaults we use key to save the data and the same key to fetch the data.

    For Example->

     NSDictionary * dataDictionary=@{@"name":@"jay",
                              @"password":@"password"};
    
     NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
                    
                 [userDef setObject:dataDictionary forKey:@"record"];

     
    Here we are making an instance of NSUserDefault i.e userDef and with the help of key we are saving some data i.e. dataDictonry.


    When we have to fetch the data then we have to use the same key. We can fetch data in any class where we want to use.

     

    NSDictionary *recordsFromUserDef = [[NSUserDefaults standardUserDefaults] objectForKey:@"record"]; //used for fetch values


    Here we are fetching the data and saving it in a dictionary i.e recordFromUserDef.

    Now the data we saved in NSUserDefault can be read any time,it won’t be omitted.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: