iOS starter SandBox Plist nsuserdefault

Source: Internet
Author: User

1. Read data from application sandbox, plist, Nsuserdefault

- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.Nsarray *addcontent = [Nsarray arraywithobjects:@" One",@" Both",@"three", nil]; //--The file path of the sandboxNsarray *patharray =nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES); NSString*path = [Patharray objectatindex:0]; //--Full path to the fileNSString *filepath = [path stringbyappendingpathcomponent:@"user.plist"]; //--Extract the dictionaryNsmutabledictionary *rootarray =[Nsmutabledictionary Dictionarywithcontentsoffile:filepath]; //NSLog (@ "%@", Rootarray);[Rootarray setobject:addcontent forkey:@"Data"]; //--Determine if a key value exists in the dictionary    if(! [Rootarray Objectforkey:@"data1"]) {[Rootarray setobject:addcontent forkey:@"data1"]; }        //--Save the dictionary to a file[Rootarray Writetofile:filepath Atomically:yes]; //--Read again to compare whether the data is writtenRootarray =[Nsmutabledictionary Dictionarywithcontentsoffile:filepath]; //NSLog (@ "%@", Rootarray); //----------------------------------------------------------------------    // --     //NSString *bundlepath = [[NSBundle mainbundle] Pathforresource:@"userlist"OfType:@"plist"]; Nsmutabledictionary*dic =[Nsmutabledictionary Dictionarywithcontentsoffile:bundlepath]; NSLog (@"%@", DIC); [DiC setobject:addcontent Forkey:@"Data"];    [DiC Writetofile:bundlepath Atomically:yes]; DiC=[Nsmutabledictionary Dictionarywithcontentsoffile:bundlepath]; NSLog (@"%@", DIC); //----------------------------------------------------------------------    // --     //Nsuserdefaults *defaults =[Nsuserdefaults Standarduserdefaults]; //[Defaults setobject:@ "value1" forkey:@ "ValueKey1"];NSString *read = [Defaults objectforkey:@"Valuekey"]; NSString*READ1 = [Defaults objectforkey:@"ValueKey1"]; NSLog (@"-- %@ -- %@", read, read1);}

iOS starter SandBox Plist nsuserdefault

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.