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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:01:17+00:00 2026-05-22T12:01:17+00:00

So, my scenario is this: I have an NSManagedObject subclass in my iOS application,

  • 0

So, my scenario is this:

I have an NSManagedObject subclass in my iOS application, and as a property I want to store the contents of an MKPolygon object. The way I’ve decided to go about this (and whether it’s valid is perhaps a different question) is to declare the polygon property as a transformable object, then store an NSArray containing the polygon’s points (as an NSValue object).

To this end, I’ve written a couple of convenience class methods on my model object:

+ (NSArray *)coordsArrayFromMKPolygon:(MKPolygon *)polygon pointCount:(int)count
{
    CLLocationCoordinate2D *coords = (CLLocationCoordinate2D *)malloc(sizeof(CLLocationCoordinate2D) * count);
    [polygon getCoordinates:coords range:NSMakeRange(0, count)];
    NSMutableArray *coordsArray = [NSMutableArray array];
    for (int i = 0; i < count; i++) {
        NSValue *coordVal = [NSValue valueWithBytes:&coords[i] objCType:@encode(CLLocationCoordinate2D)];
        [coordsArray addObject:coordVal];
    }
    free(coords);
    return [NSArray arrayWithArray:coordsArray];
}

+ (MKPolygon *)polygonFromCoordsArray:(NSArray *)coordsArray pointCount:(int)count
{
    CLLocationCoordinate2D *coords = (CLLocationCoordinate2D *)malloc(sizeof(CLLocationCoordinate2D) * count);
    for (int i = 0; i < count; i++) {
        CLLocationCoordinate2D coord;
        [[coordsArray objectAtIndex:i] getValue:&coord];
        coords[i] = coord;
    }
    free(coords);
    return [MKPolygon polygonWithCoordinates:coords count:count];
}

I can just call these methods on my MKPolygon objects before saving or loading an instance of the model, but I’d like to override the dynamic getters and setters in the model itself, so that I can just say something like [turf setTurf_bounds:polygon] (where polygon is an MKPolygon instance).

What I’d really like is to be able to do something like this:

- (void)setTurf_bounds:(id)turf_bounds
{
    MKPolygon *poly = (MKPolygon *)turf_bounds;
    NSArray *coordsArray = [Turf coordsArrayFromMKPolygon:poly pointCount:[poly pointCount]];
    // Save the converted value into the @dynamic turf_bounds property
}

- (id)turf_bounds
{
    // grab the contents of the @dynamic turf_bounds property into say, NSArray *coordsArray
    return [Turf polygonFromCoordsArray:coordsArray pointCount:[coordsArray count]];
}

But I’ve had no joy so far. Calling [super setValue:coordsArray forKey:@"turf_bounds"] or its getter counterpart doesn’t work, nor does trying to write it as self.turf_bounds (which just recursively calls my overridden setters).

Am I going about this completely the wrong way, or just missing something?

  • 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-22T12:01:18+00:00Added an answer on May 22, 2026 at 12:01 pm

    Never call [super valueForKey:..] in a NSManagedObject subclass! (unless you implemented them in a superclass yourself)
    Instead use the primitive accessor methods.

    Sample getter/setter implementation from ADC:

    @interface Department : NSManagedObject
    @property(nonatomic, strong) NSString *name;
    @end
    
    @interface Department (PrimitiveAccessors)
    - (NSString *)primitiveName;
    - (void)setPrimitiveName:(NSString *)newName;
    @end
    
    
    @implementation Department
    
    @dynamic name;
    
    - (NSString *)name
    {
        [self willAccessValueForKey:@"name"];
        NSString *myName = [self primitiveName];
        [self didAccessValueForKey:@"name"];
        return myName;
    }
    
    - (void)setName:(NSString *)newName
    {
        [self willChangeValueForKey:@"name"];
        [self setPrimitiveName:newName];
        [self didChangeValueForKey:@"name"];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this typical scenario. I have a smartclient application built on .net 2.0
I have this scenario with GIT: I want to do something with a specific
I have this scenario where I want to display the xml which is coming
I have this scenario where I want to share the column size among all
The scenario is this: I have Java swing application with JFrame. There is textarea
Basically I have this scenario going on: //in interface header @property(nonatomic,retain)OtherClass *otherClass; //implementation -
I have this scenario where I need data integrity in the physical database. For
we have this scenario: A server which contains needed data and client component which
The scenario is this We have two applications A and B, both which are
My scenario is this: I have a base NHibernate query to run of the

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.