iOS Dev-store use preferences preference storage

Source: Internet
Author: User

① many iOS apps support preferences such as saving usernames, passwords, font size, and more, iOS offers a standard set of solutions to add preferences to your app
② Each app has a Nsuserdefaults instance that accesses preferences
③ For example, save user name, font size, automatic login

Save method

-(Ibaction) Save {//1With Nsuserdefaults, you have direct access to the software's preferences (library/preferences) nsuserdefaults *defaults = [nsuserdefaults    Standarduserdefaults]; //2. storing data [defaultsSetobject:@"MJ"  forkey:@"Account"]; [DefaultsSetobject:@"123"  forkey:@"PWD"]; [DefaultsSetInteger:Ten  forkey:@"Age"]; [DefaultsSetBool:yes forkey:@"Auto_login"]; //3. sync now [defaults synchronize];}

Note: When setting the data, Userdefaults does not write immediately, but instead writes the cached data to the local disk according to the timestamp. So after calling the set method, it is possible that the data has not yet been written to the disk application to terminate. The above problem can be forced by calling the Synchornize method to write

Read

- (IBAction)read {    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];    NSString *account = [defaults objectForKey:@"account"];    BOOL autoLogin = [defaults boolForKey:@"auto_login"];}

iOS Dev-store use preferences preference storage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.