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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:21:57+00:00 2026-06-10T22:21:57+00:00

I don’t understand why I can archive CGPoint structs but not CLLocationCoordinate2D structs. What’s

  • 0

I don’t understand why I can archive CGPoint structs but not CLLocationCoordinate2D structs. What’s the difference to the archiver?

Platform is iOS. I’m running in the simulator and haven’t tried on the device.

// why does this work:
NSMutableArray *points = [[[NSMutableArray alloc] init] autorelease];
CGPoint p = CGPointMake(10, 11);
[points addObject:[NSValue valueWithBytes: &p objCType: @encode(CGPoint)]];
[NSKeyedArchiver archiveRootObject:points toFile: @"/Volumes/Macintosh HD 2/points.bin" ];

// and this doesnt work:
NSMutableArray *coords = [[[NSMutableArray alloc] init] autorelease];
CLLocationCoordinate2D c = CLLocationCoordinate2DMake(121, 41);
[coords addObject:[NSValue valueWithBytes: &c objCType: @encode(CLLocationCoordinate2D)]];
[NSKeyedArchiver archiveRootObject:coords toFile: @"/Volumes/Macintosh HD 2/coords.bin" ];

I get a crash on the 2nd archiveRootObject and this message is printed to the console:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSKeyedArchiver encodeValueOfObjCType:at:]: this archiver cannot encode structs'
  • 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-10T22:21:58+00:00Added an answer on June 10, 2026 at 10:21 pm

    OK, Tom, are you ready for some geek-ness? I’m an “older” guy in this world of young whippersnappers. However, I remember a few things about C, and I’m just a geek at heart.

    Anyway, there is a subtle difference between this:

    typedef struct { double d1, d2; } Foo1;
    

    and this:

    typedef struct Foo2 { double d1, d2; } Foo2;
    

    The first is a type alias to an anonymous structure. The second is a type alias to struct Foo2.

    Now, the documentation for @encode says that the following:

    typedef struct example {
        id   anObject;
        char *aString;
        int  anInt;
    } Example;
    

    will result in {example=@*i} for both @encode(example) or @encode(Example). So, this implies that @encode is using the actual struct tag. In the case of a typedef that creates an alias to an anonymous struct, it looks like @encode always returns ?‘

    Check this out:

    NSLog(@"Foo1: %s", @encode(Foo1));
    NSLog(@"Foo2: %s", @encode(Foo2));
    

    Anyway, can you guess how CLLocationCoordinate2D is defined? Yep. You guessed it.

    typedef struct {
    CLLocationDegrees latitude;
    CLLocationDegrees longitude;
    } CLLocationCoordinate2D;
    

    I think you should file a bug report on this. Either @encode is broken because it does not use alias typedefs to anonymous structs, or CLLocationCoordinate2D needs to be fully typed so it is not an anonymous struct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know why but font is not displaying.Please help. CSS(in css folder): style.css: @font-face
I don't know if this question is trivial or not. But after a couple
Don't know if I'm over-thinking this or not.. but I'm trying to be able
I don't get to see the source code but the .class file. Can I
Don't ask me why but i can't use this method because I need to
Don't know why but I can't find a solution to this. I have 3
Don't understand why #include <Header.h> is not compiling while #include Header.h is compiling with
Don't quite understand why this copy constructor is not invoked when I build with
don't know if the title describes anything about what I'm trying to say but
Don't ask me how but I'm in a situation where I have DCPs published

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.