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