Sandbox, plist file, preferences

Source: Internet
Author: User






Preferred settings:



Application Package: (layer in) contains all the resource files and Executables documents: saves data that needs to be persisted when the app is run, and the directory is backed up when itunes synchronizes the device. For example, a game app can save a game archive in this directory, TMP: Save the temporary data needed to run the app, and then delete the corresponding file from that directory when it's finished. When the app is not running, the system may also purge files in that directory. itunes syncs the device without backing up the directory Library/caches: saves data that needs to be persisted when the app runs, and itunes syncs the device without backing up the directory. Non-critical data with large storage volumes and no backup required Library/preference: Save all preferences for your app, and the iOS settings (settings) app will find the app's settings information in that directory. This directory is backed up when itunes syncs the device


plist File Details:
#import "ViewController.h" #import "Contact.h" @interface Viewcontroller () @property (nonatomic,copy) NSString *        Plistpath; @end @implementation viewcontroller-(NSString *) plistpath{if (!_plistpath) {//Get document Directory                NSString *doc = [Nssearchpathfordirectoriesindomains (nsdocumentdirectory, Nsuserdomainmask, YES) lastObject];        NSLog (@ "%@", Doc);    _plistpath = [Doc stringbyappendingpathcomponent:@ "Data.plist"]; } return _plistpath;}    -(void) viewdidload {[Super viewdidload];       Additional setup after loading the view, typically from a nib. View the path of the sandbox//1. The path of the console print sandbox, use finder-to go to-folder to open//2. Console print the path to the sandbox, open terminal open + path//3. Use the Simpholders tool//4. You can enter the PO NS with a breakpoint HomeDirectory ()//Get Cache Path (cache) NSString *cachepath = [Nssearchpathfordirectoriesindomains (Nscachesdirectory, NS    Userdomainmask, YES) lastobject];            NSLog (@ "%@", CachePath);    Get temporary path (tmp) NSString *tmppath = Nstemporarydirectory (); NSLog (@ "%@ ", Tmppath);    Home directory NSString *homepath = Nshomedirectory ();        NSLog (@ "%@", HomePath);    }-(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{[self teststring];    Not all objects have access to the Write method contact *contact = [[Contact alloc] init];    Contact.name = @ "Zhangsan";        }-(void) teststring{nsstring *data = @ "AABC";        Write string [data WriteToFile:self.plistPath atomically:yes encoding:nsutf8stringencoding Error:nil];    Read string NSString *str = [NSString stringWithContentsOfFile:self.plistPath encoding:nsutf8stringencoding Error:nil];        NSLog (@ "%@", str);        }-(void) testdictionary{//Save the data to a plist file in the sandbox nsdictionary *data = @{@ "name": @ "Zhangsan" @ "Age": @23};            Write data to a file [data WriteToFile:self.plistPath Atomically:yes];    Read Nsdictionary *dict = [Nsdictionary DictionaryWithContentsOfFile:self.plistPath]; NSLog (@ "%@", Dict);} /** * Test array stored in a plist file */-(void) testarray{//Save data to a plist file in the sandbox nsarray *data = @[@"ASD", @ "ASDs"];            Write data to a file [data WriteToFile:self.plistPath Atomically:yes];    Read Nsarray *array = [Nsarray ArrayWithContentsOfFile:self.plistPath]; NSLog (@ "%@", array);}


Detailed User preferences:
-(void) viewdidload {[Super viewdidload];     Additional setup after loading the view, typically from a nib. [Self modify];}    -(void) modify{//Modify user preferences data nsuserdefaults *defaults = [Nsuserdefaults standarduserdefaults];    [Defaults setobject:@ "321" forkey:@ "password"]; [Defaults synchronize];}    -(void) delete{//delete user preferences data nsuserdefaults *defautls = [Nsuserdefaults standarduserdefaults];        [Defautls removeobjectforkey:@ "account"];    Delete Remember also to call the method of synchronization [Defautls synchronize];    }-(void) read{//Read user preferences data nsuserdefaults *defautls = [Nsuserdefaults standarduserdefaults];    NSString *account = [Defautls objectforkey:@ "account"];    NSString *password = [defautls objectforkey:@ "password"];    BOOL rememberpwd = [Defautls boolforkey:@ "Rememberpwd"];    BOOL autologin = [Defautls boolforkey:@ "Autologin"]; NSLog (@ "%@%@%d%d", account,password,rememberpwd,autologin);} -(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{//Use PreferencesSave data Nsuserdefaults *defaults = [Nsuserdefaults standarduserdefaults];    Saved data [defaults setobject:@ "Zhangsan" forkey:@ "account"];    [Defaults setobject:@ "123" forkey:@ "password"];    [Defaults setbool:yes forkey:@ "Autologin"];        [Defaults setbool:yes forkey:@ "Rememberpwd"]; Call the synchronous method and save the data to the sandbox file [defaults synchronize];}




Sandbox, plist file, preferences

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.