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
Post a Comment