Plist file multiple reads and writes, the localization processing of iOS data, realizes the localization processing of small amount of data

Source: Internet
Author: User

Say less nonsense, directly on the code:

 (void) Viewdidload {[Super viewdidload]; Read the files in the program folder of the Plist file, and note that the file of the program file can only be read and not written, only in the program sandbox; nsstring *plistpath = [[NSBundle mainbundle] pathforresource:@ "    Plisttest "oftype:@" plist "];    NSLog (@ "This is the path to the plist file%@", Plistpath);    Nsmutabledictionary *data = [[Nsmutabledictionary alloc] initwithcontentsoffile:plistpath];            NSLog (@ "This is the content of the plist file%@", data);    Add data description, can be modified; [Data setobject:@ "I am in Tohoku University" forkey:@ "Address"];    [Data setobject:@ "male" forkey:@ "sex"]; Gets the path of the document to which the sandbox is applied; Nsarray *paths = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask,    YES);        nsstring* plistPath1 = [Paths objectatindex:0]; Here to set the name of the file to complete the path, note that the file memory modification is done in memory, and then directly update the current data once, thus reducing the number of read and write files NSString *filename =[plistpath1    stringbyappendingpathcomponent:@ "Plisttest.plist"];        NSLog (@ "This is the path in the sandbox%@", filename);        Write file [data writetofile:filename Atomically:yes];        NSLog (@ "proves that my data is really written in it"); Certificate File Write Success Nsmutabledictionary *afterdata = [[Nsmutabledictionary alloc] initwithcontentsoffile:filename];        NSLog (@ "This is a case of writing data%@", afterdata);        NSLog (@ "program End"); Do any additional setup after loading the view, typically from a nib.}

The operating result is:

2015-04-26 12:08:55.857 plist[1702:112934] This is the path to the plist file/users/xuyaowen/library/developer/coresimulator/devices/ 6bd2a547-cc45-4739-9578-c1d268c26b20/data/containers/bundle/application/28977ea1-0f6a-4b4f-af37-f6badeeb889c/ Plist.app/plisttest.plist2015-04-26 12:08:55.868 plist[1702:112934] This is the contents of the plist file {info = "\u8fd9\u662f\u6211\    U7684plist\u6587\u4ef6 ";    name = Xiaohongqi; Password = Xiaohongqi;} 2015-04-26 12:08:55.869 plist[1702:112934] This is the path in the sandbox/users/xuyaowen/library/developer/coresimulator/devices/ 6bd2a547-cc45-4739-9578-c1d268c26b20/data/containers/data/application/f145b509-73b0-4266-ae06-94f2b0a56a7c/ Documents/plisttest.plist2015-04-26 12:08:55.902 plist[1702:112934] prove that my data really had to be written in it 2015-04-26 12:08:55.902 plist[    1702:112,934] This is the case where the data was written {address = "\u6211\u5728\u4e1c\u5317\u5927\u5b66";    info = "\u8fd9\u662f\u6211\u7684plist\u6587\u4ef6";    name = Xiaohongqi;    Password = Xiaohongqi; Sex = "\u7537";} 2015-04-26 12:08:55.902 plist[1702:112934] program end


Then pass the log content at the end of the run to prove success!


Go to Folder: Copy the path to access the files in the program sandbox, pay attention to improve their ability!

Plist file multiple reads and writes, the localization processing of iOS data, realizes the localization processing of small amount of data

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.