ios - how to save an NSMutableArray to local storage -


i want save nsmutablearray file , load every time program runs. best solution this?

this example:

// add new item arraylist nsstring *textnewcategory = [alert textfieldatindex:0].text; [arraylist insertobject:textnewcategory atindex:0];  // save arraylist usercategory = [nsuserdefaults standarduserdefaults]; [usercategory setobject:arraylist forkey:@"newcategory"]; nslog(@"arraylist 1:%d", arraylist.count); // ex: in case, has count : 30  //in viewdidload, array saved before  usercategory = [nsuserdefaults standarduserdefaults]; arraynewcategory = [[nsmutablearray alloc] initwitharray: [usercategory objectforkey:@"newcategory"]]; arraylist = arraynewcategory; nslog(@"arraylist 2:%d", arraylist.count); // in moment, has count: 29. 

i don't understand why re-loaded array has 29 items instead of 30 expect.

save array plist:

[array writetofile:path atomically:no] 

and retrieve it:

nsmutablearray *array = [[nsmutablearray alloc] initwithcontentsoffile:path]; 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -