iphone - NSUserDefault to NSArray -
icstored value of 2 label in nsuserdefault, trought nsmutablearray.
nsuserdefaults *userdefaults = [nsuserdefaults standarduserdefaults]; // add bookmark nsmutabledictionary *bookmark = [nsmutabledictionary new]; [bookmark setvalue:author.text forkey:@"author"]; [bookmark setvalue:book.text forkey:@"book"]; [bookmarks addobject:bookmark]; // save (updated) bookmarks [userdefaults setobject:bookmarks forkey:@"bookmarks"]; [userdefaults synchronize];
now problem how retrieve values of nsuserdefault trought nsarray?
nsuserdefaults *prefs = [nsuserdefaults standarduserdefaults]; self.dataarray = [prefs arrayforkey:@"bookmarks"]; nsstring *author = ?? nsstring *book = ??
nsstring * author = [self.dataarray objectforkey: @"author"]; nsstring * book = [self.dataarray objectforkey: @"book"];
this assumes saved array , re-loaded array nsuserdefaults
. should error checking in code.
Comments
Post a Comment