Saving Multiple Annotations -NSUserDefaults

Posted by casillas on Stack Overflow See other posts from Stack Overflow or by casillas
Published on 2012-10-04T02:28:58Z Indexed on 2012/10/04 3:37 UTC
Read the original article Hit count: 518

Filed under:
|
|

I came cross this code as shown below.In the following code, I could able to save only one single annotation, however I have an array of annotations, I could not able to save them with single NSUserDefaults

  To save:

    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    [ud setDouble:location.latitude forKey:@"savedCoordinate-latitude"];
    [ud setDouble:location.longitude forKey:@"savedCoordinate-longitude"];
    [ud setBool:YES forKey:@"savedCoordinate-exists"];
    [ud synchronize];

Edited:

 -(void)viewDidLoad
        NSUserDefaults *ud=[NSUserDefaults standardUserDefaults];
            if([ud boolForKey:@"save-exist"])
            { NSMutableArray *udAnnotations=[[NSMutableArray alloc]initWithArray:
[ud objectForKey:@"annotationsArray"]];
                NSLog(@"%d",[udAnnotations count]);
            }
            else{
            [self addAnno];
            }

    -(void)addAnno
    {

    [mapView addAnnotations:annotationArray];
    NSUserDefaults *ud=[NSUserDefaults standardUserDefaults];
    [ud setObject:annotationArray forKey:@"annotationsArray"];
    [ud setBool:YES forKey:@"save-exist"];
    [ud synchronize];

}

© Stack Overflow or respective owner

Related posts about ios

Related posts about nsuserdefaults