Primary data Persistence (sandbox)

Source: Internet
Author: User

1- (void) Viewdidload {2 [Super Viewdidload];3     //Do any additional setup after loading the view.4Self.view.backgroundColor =[Uicolor Whitecolor];5     6     7     //Sandbox: System assigns a folder to each application, the folder name is random, others cannot access8     9NSString *sandboxpath =nshomedirectory ();TenNSLog (@"%@", Sandboxpath); One      A     //There are 3 folders under the sandbox file, namely the documents Library TMP -      -     /* the 1.Documents content Under this file is uploaded to icloud, and icloud allocates 5G for each user, typically to store some user information, game progress information -       - 2. Get the Documents folder Road strength -       +      */ -      +     /** A * < #Description #> at      * - * @param nsdocumentdirectory the path of which folder to search - * @param nsuserdomainmask Search in that file system - * @param yes to get the absolute path (YES) relative path (NO) -      * - * @return in      */ -      toNsarray *documentarray =nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES); +      - //NSLog (@ "%@", Documentarray); the      *     //An array has an element $NSString *mydocpath =[Documentarray Firstobject];Panax Notoginseng      - //NSLog (@ "%@", Mydocpath); the      +      A      the     //the Library folder has two sub-files Caches (cache) Preferences +      -     //Library Folder path $Nsarray *libraryarray =nssearchpathfordirectoriesindomains (Nslibrarydirectory, Nsuserdomainmask, YES); $      -NSString *librarypath = libraryarray[0]; -      the //NSLog (@ "%@", LibraryPath); -     Wuyi      the      -     //get the path to the caches folder generally put some cache files, network cache and so on Wu      -Nsarray *cachesarray =nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES); About      $NSString *cacherpath =[Cachesarray Lastobject]; -      - //NSLog (@ "%@", Cacherpath); -  A      +     //Get Preferences folder path the      - //Nsarray *preferencesarray = Nssearchpathfordirectoriesindomains (Nspreferencepanesdirectory, NSUserDomainMask, YES); $ //     the //nsstring *preferencespath1 = [Preferencesarray lastobject]; the      theNSString *preferencespath = [Sandboxpath stringbyappendingstring:@"/library/preferences"] ; theNSString *preferencespath1 = [LibraryPath stringbyappendingpathcomponent:@"Preferences"] ; -      in //NSLog (@ "%@", Preferencespath); the      the      About  the     //get the path to the TEM folder (temporary files, such as compressed packets after the download, and delete them after the extract is finished) the      the     //get the TMP directory +      -     //getting the application's TMP directory is much easier than getting the documents directory. Use the function nstemporarydirectory () to get the TMP directory path.  the     Bayinsstring* TempPath =nstemporarydirectory (); the      the     //gets the full path of the file.  -      -nsstring* tempfile = [TempPath stringbyappendingpathcomponent:@"properties.plist"]; the      theNSLog (@"%@", TempPath); the // the      -     //. App IOS8 exists in the sandbox file before the     //The executable file of the current application, that is, NSBundle, in the process of compiling the program, will be all of their files are packaged into NSBundle, these files are read-only the      the     //get the path to the. App file94NSString *apppath =[[NSBundle Mainbundle]resourcepath]; the //NSLog (@ "*********%@", AppPath); the      the     //get the path to an. app file98NSString *infoplistpath = [[NSBundle mainbundle]pathforresource:@"Info"OfType:@"plist"]; AboutNsdictionary *dic =[[Nsdictionary Alloc]initwithcontentsoffile:infoplistpath]; -     101NSLog (@"%@", DIC);102     103     104      the     //read-write Simple file NSString nsdictionary Nsarray NSData can be written directly to local106     107     //writes a string to the local108     /*109 1. First you need to know where the file (string) is written in, that is, the path the 2. Need to know which file is written111 3. Method of writing string calls the      */113      the     //The path where the file was written (the name of the file is appended to it), but there is no file at this time the     //What 's written in the back will overwrite the previous the     117NSString *filepath = [Mydocpath stringbyappendingpathcomponent:@"document. txt"];118     119 //nsstring *fiel = @ "What the devil"; -     121NSString *fiel1 =@"Ah";122     123     /*124 fiel files written by the parameter 1: path126 Parameter 2: Whether you need to protect the file being written127 Parameter 3: encoding format - Parameter 4: Error message129      */ the     131Nserror *error =Nil; the[Fiel1 writetofile:filepath atomically:yes encoding:nsutf8stringencoding error:&ERROR];133     134 //NSLog (@ "%@", FilePath);135     136     137     //read files using a path138     139NSString *readfiel =[[NSString Alloc]initwithcontentsoffile:filepath encoding:nsutf8stringencoding Error:nil]; $     141NSLog (@"%@", Readfiel);142     143     144     145     //Read and write arrays146     147NSString *arrfielpath = [Cacherpath stringbyappendingpathcomponent:@"arr.plist"] ;148     149Nsarray *arrfiel = @[@"123",@"111",@"5458444",@"9999",@"4444"]; Max     151 [Arrfiel Writetofile:arrfielpath atomically:yes]; the     153 //NSLog (@ "%@", Arrfielpath);154     155     //reading an array locally156Nsarray *readarr =[[Nsarray Alloc]initwithcontentsoffile:arrfielpath];157NSLog (@"%@", Readarr);158     159      the     //read/write Dictionaries161NSString *dicfielpath = [preferencesPath1 stringbyappendingpathcomponent:@"preferen.plist"];162     163Nsdictionary *dic1 = @{@"A2":@" +",@"B3":@" A",@"C4":@" at"};164     165 [Dic1 Writetofile:dicfielpath atomically:yes];166     167 //NSLog (@ "%@", Dicfielpath);168     169Nsdictionary *dic2 =[[Nsdictionary Alloc]initwithcontentsoffile:dicfielpath]; theNSLog (@"%@", dic2);171 172}

Primary data Persistence (sandbox)

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.