iphone - Creating Files And Saving Objects In Them -


why when call method (saveobject: (id)object forkey: (nsstring *) key), file not created???

when call filepath equal nil (-(void) setfilepath: (nsstring *)filename) method called...

-(int) saveobject: (id)object forkey: (nsstring *) key {     //save object file      if(filepath == nil) {         [self setfilepath:nil];     }      maindict = [nsmutabledictionary dictionarywithcontentsoffile:filepath];     if(maindict == nil) {         maindict = [[nsmutabledictionary alloc] init];     }      [maindict setobject:object forkey:key];      if(![maindict writetofile:filepath atomically:yes]) {         if(object == nil) {             return 3;         }         if(key == nil) {             return 4;         }         return 2; //error not write object file     } else {         if(shouldusecache == yes) {             cachestatus = 2; //new caches need updated         }         return 1; //success object saved file     }      //return key's     // *1 success object saved file     // *2 error not write object file     // *3 error object variable = nil     // *4 error key variable = nil }  -(void) setfilepath: (nsstring *)filename {     paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);     documentsdirectory = [paths objectatindex:0];     if(filename == nil) {         filename = @"savedobjects";     }     filepath = [nsstring stringwithformat:@"%@/%@.plist",documentsdirectory, filename]; } 

i think problem contents of dictionary intending write. adding object dictionary. object must contain members of types:nsarray , nsdictionary , nsstring , nsdate, nsdata , nsnumber. if object contains int or float , or other these , won't write.

you can read more here


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -