/** * 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)