Sunday 15 February 2015

ios - Store and Retrive Coordinates in NSUserDefaults -



ios - Store and Retrive Coordinates in NSUserDefaults -

i have number of cities in mutablearray, , getting coordinates of these cities , pass through nsuserdefault.the next effort not print out coordinates. there other way store , retrive set of coordinates?

points = [[nsmutablearray alloc] init]; (int = 0; < mycities.count; i++) { double lati = [[[responseobject objectforkey:@"coord"] valueforkey:@"lat"] doublevalue]; double longi = [[[responseobject objectforkey:@"coord"] valueforkey:@"lon"] doublevalue]; cllocationcoordinate2d new_coordinate = cllocationcoordinate2dmake(lati, longi); [points addobject:[nsvalue valuewithmkcoordinate:new_coordinate]]; } /// store nsuserdefaults *userdefaults = [nsuserdefaults standarduserdefaults]; nsdata *data = [nskeyedarchiver archiveddatawithrootobject:points]; [userdefaults setobject:data forkey:@"key"]; [userdefaults synchronize]; // retrive coordinates in other viewcontroller nsuserdefaults *userdefaults = [nsuserdefaults standarduserdefaults]; nsdata* info = [userdefaults objectforkey:@"key"]; nsvalue *unarchived = [nskeyedunarchiver unarchiveobjectwithdata:data]; nslog(@"%@", unarchived);

ios nsuserdefaults

No comments:

Post a Comment