Data access for IOS plist (Shahe directory)

Source: Internet
Author: User

/** * Click the save button*/-(Ibaction) Savedatabtnclick: (ID) Sender {//YouTube Practices//nsstring *path = @ "/users/apple/library/application support/iphone simulator/7.1/applications/        A6d53e11-ddf0-4392-b2d4-fe77a96888a6/documents/abc.plist ";  //  get application Shahe directory nsstring *home = nshomedirectory (); //do not recommend writing///nsstring *path = [Home stringbyappendingstring:@ "/documents"]; //do not suggest that documents be written dead//nsstring *path = [Home stringbyappendingpathcomponent:@ "Documents"]; //Nsuserdomainmask Looking in the user directory//YES represents the user directory's ~//nsdocumentdirectory Find Documents folder //  It is recommended to use the following method to dynamically obtain nsstring *doc = [Nssearchpathfordirectoriesindomains (NSDocumentDirectory,    Nsuserdomainmask, YES) lastobject];  //  Stitching file path nsstring *path = [doc stringbyappendingpathcomponent:@ "abc.plist "]    ; NSLog (@"%@", path);//Nsarray *arr = @[@ "Lnj", @ " " ";//[arr Writetofile:path atomically:yes]; //nsdictionary *dict = @{@ "name": @ "LNJ", @ "age": @ "28"};  //  call WriteToFile to write data to file //[Dict Writetofile:path atomically:yes];        /*plist can only store some of the regular classes that the system comes with, that is, objects that have writetofile methods to save data strings/dictionaries/data/nsnumber/nsdata using plist ...*/        //Custom objects cannot be saved to plistNjperson *p =[[Njperson alloc] init]; P.name=@"LNJ"; Nsdictionary*dict = @{@" Person":@"ABC"}; [Dict Writetofile:path atomically:yes];}/** * Click the read button*/-(Ibaction) Readdatabtnclick: (ID) Sender {NSString*doc =[Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) lastobject]; NSString*path = [Doc stringbyappendingpathcomponent:@"abc.plist"]    ;  //  read Data Nsdictionary *dict =[Nsdictionary Dictionarywithcontentsoffile:path]; NSLog (@"%@", dict);}

Data access for IOS plist (Shahe directory)

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.