1, the need to save the information has been saved in plist file form on the local, that is, write to the sandbox:
/** * write to local (plist file) */-(void) savearray{ //1. Get the sandbox root path nsstring *home = Nshomedirectory (); 2.document path nsstring *docpath = [Home stringbyappendingpathcomponent:@ "Documents"]; 3. New data nsdictionary *dict = @{@ "haha": @ "one", @ "hehe": @ "", @ "Huhu": @ "@" @ " Gogo": @ "+"} ; NSString *filepath = [DocPath stringbyappendingpathcomponent:@ "Data.plist"]; [Dict Writetofile:filepath atomically:yes];}
Where decuments is the sandbox fixed path, data.plist is to take the name of the file to be saved;
2, when need to take out the saved information, read the plist file saved in the Local:
/** * Read Write local plist file */-(ibaction) Read { //1. Get sandbox root path nsstring *home = Nshomedirectory (); 2.document path nsstring *docpath = [Home stringbyappendingpathcomponent:@ "Documents"]; 3. File path nsstring *filepath = [DocPath stringbyappendingpathcomponent:@ "Data.plist"]; 4. Read Data nsdictionary *dic = [Nsdictionary Dictionarywithcontentsoffile:filepath]; NSLog (@ "%@", DIC);}
3, sometimes saved in the local file information is not up-to-date, you need to delete the last saved in the local file, and then re-save the latest information on the Local:
/** * Delete data stored in the local plist file */-(void) remove{ //1. Get the sandbox root path nsstring *home = Nshomedirectory (); 2.document path nsstring *docpath = [Home stringbyappendingpathcomponent:@ "Documents"]; 3. File path nsstring *filepath = [DocPath stringbyappendingpathcomponent:@ "Data.plist"]; Nsfilemanager *filemanager = [Nsfilemanager Defaultmanager]; [FileManager Removeitematpath:filepath error:nil];}
This completes the local storage of the file.
For small file storage, reduce the trouble with database storage, to plist file storage, light, fast, easy to operate.
Sometimes for the network data cache, if the data is not very dozen, but also can be stored with the plist file.
Local storage with plist files