Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8621897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:55:23+00:00 2026-06-12T06:55:23+00:00

I came cross this code as shown below.In the following code, I could able

  • 0

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];

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:55:25+00:00Added an answer on June 12, 2026 at 6:55 am

    As you already have an array, simply use setObject:forKey: and arrayForKey:

    As the objects in your original array are not a type that can be saved directly, store their data in dictionaries:

    NSMutableArray *saveData = [[NSMutableArray alloc] initWithCapacity:originalData.count];
    for(id location in originalData) {
        [saveData addObject:@{@"lat":[location latitude], @"lon":[location longitude]}];
    }
    [[NSUserDefaults standardUserDefaults] setObject:saveData forKey:@"annotationsArray"];
    

    and convert on retrieval:

    NSMutableArray *restoredData = [[NSMutableArray alloc] init];
    for(NSDictionary *data in [[NSUserDefaults standardUserDefaults] arrayForKey:@"annotationsArray"]) {
        [restoredData addObject:[[Location alloc] initWithLat:data[@"lat"] andLon:data[@"lon"]]];
    }
    // if restoredData.count is 0, there were no stored objects.
    

    A couple notes:

    • If you’re not using ARC, remember to release the alloc’d objects.
    • This uses the new objective c object literal syntax and dictionary access syntax. If you aren’t using xcode 4.5 you’ll need to construct and access them the traditional way, dictionaryWithObjectsAndKeys: and objectForKey:
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came cross this code as shown below. how could I save existing annotation
I just came a cross this nice code that makes this scatter matrix plot:
I came across this code today and don't really understand it. Please could someone
Came across this code: <?php require_once 'HTTP/Session/Container/DB.php'; $s = new HTTP_Session_Container_DB('mysql://user:password@localhost/db'); ini_get('session.auto_start') or session_start();
I came across this Linq to Sql code in an application I am maintaining:
Came across this conditional in some uncommented Objective-C code: if (w & (w -
I have this very long exercise and I came a cross a problem in
I just came cross puppet inheritance lately. A few questions around it: is it
I'm currently designing an API and I came a cross a little problem: How
(Came up with this question in the course of trying to answer this other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.