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 6652145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:06:00+00:00 2026-05-26T01:06:00+00:00

In my app I am trying to store an array of MKPolylines into NSUserDefaults

  • 0

In my app I am trying to store an array of MKPolylines into NSUserDefaults.

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:overlays];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"theKey"];

Gives:

[MKPolyline encodeWithCoder:]: unrecognized selector sent to instance 0x169c20`
Terminating app due to uncaught exception 
'NSInvalidArgumentException', reason: '-
[MKPolyline encodeWithCoder:]: unrecognized 
selector sent to instance 0x1c57e0'

Edit: I made some progress. MKPolylineView conforms to the NSCoding protocol, so I have converted my array of MKPolylines into an array of MKPolylineViews. The problem is that when I want to add them back to a map later, I can’t convert them back to MKPolylines. Any idea how to do that?

Crashes at this code:

NSData* data = [[NSUserDefaults standardUserDefaults] objectForKey:@"theKey"];
NSArray* overlays = [NSKeyedUnarchiver unarchiveObjectWithData:data];

for(MKPolylineView* a in overlays)
    [mapView addOverlay:a.overlay];

2011-10-17 21:15:56.416 Trail Tracker[4269:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x34b2f8bf 0x36c3a1e5 0x34a8420f 0x35697595 0x6257 0x62db 0x365f77ff 0x36601d53 0x36601cc1 0x366a1339 0x366a014f 0x366fad97 0x649b 0x36671565 0x366e9ce7 0x31fcc943 0x34b03a63 0x34b036c9 0x34b0229f 0x34a854dd 0x34a853a5 0x351f9fed 0x365ec743 0x2c75 0x2c34)
terminate called throwing an exception(gdb) 
  • 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-05-26T01:06:01+00:00Added an answer on May 26, 2026 at 1:06 am

    I am not pretty sure about this but the MKPolylines are made from the array of CLLocationCoordinate2D which contains float value for lat and long.

    So if you can convert this array of CLLocationCoordinate2D into array of dictionary I think than you can save those lines in your user defaults.

    You can do some thing like this

    MKMapPoint *points = overlays.points;
    
    NSMutableArray *temp = [NSMutableArray array];
    for(int i = 0; i < points.length; i++)
    {
        // Not sure for this part
        NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:points[i].x], @"x", [NSNumber numberWithFloat:points[i].y], @"y", nil];
        [temp addObject:dict];
    }
    

    Then you can use this array to store the overlay points in nsuserdefaults like this

    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:temp];
    [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"theKey"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to stick some data into the app so I can then build
I am trying to store an xml value in my app.config file. The app.config
I'm trying to upload an application to the iPhone App Store, but I get
I have a text field in my app. I am trying to store whatever
I have an app that shows store sales. It is a multi-dimensional array, so
I am trying to feed in some JSON data to my iPhone app, the
I am trying to upload my first app on the App Store, but it
I'm trying to call a PostgreSQL stored procedure from a Java app; the procedure
I've been experiencing very inconsistent results while developing an iPhone app and trying to
In my app I'm trying to render text along a path; this is fine

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.