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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:54:24+00:00 2026-06-16T19:54:24+00:00

I am having issues with my custom accessor method for a core data property

  • 0

I am having issues with my custom accessor method for a core data property on an iPhone app. I want to do a little more than just pull out the primitive type and return it. I have an NSSet of possible activityTypes and if there is no primitiveType for the object then I want to look in that set and return the activityType that matches another variable on my class.

The following is the code that I came up with for doing this. The issue with the code is that my call to [self willChangeValueForKey:@"type"] leads to an infinite loop where the program keeps spitting out the NSLog “Setting type to …” – probably because I am calling the willChange from within the accessor?

If I take out the [self willChangeValueForKey:@"type"] I do not get a loop and the program runs fine and the next time I try to access the type on the object the primitive type is correctly recalled. However, when I tell my ManagedObjectContext that it is time to save it tells me that there are no changes to any of the objects – so since I am not calling willChangeValueForKey – the change to the primitiveType is never persisted for the object.

- (ActivityType *)type {

[self willAccessValueForKey:@"type"];
ActivityType *myType = [self primitiveType];
[self didAccessValueForKey:@"type"];

if (myType != nil) {
    NSLog(@"Use primitive (%@)", [myType myDescription]);

} else {

    // 1) find type
    NSSet *types = self.myActivityTypes;

    NSSet *foundTypes = [types objectsPassingTest:^BOOL(id obj, BOOL *stop) {
        ActivityType *object = (ActivityType *) obj;

        return ([object.typeName isEqualToString:self.activityTypeName]);

    }];

    myType = [foundTypes allObjects][0];

    NSLog(@"Setting type to %@", [myType myDescription]);

    // in this case we should not alert anyone since we are inside the getter?
    [self willChangeValueForKey:@"type"];
    [self setPrimitiveType:myType];
    [self didChangeValueForKey:@"type"];


}

return myType;

}
  • 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-16T19:54:26+00:00Added an answer on June 16, 2026 at 7:54 pm

    The managed object property observing mechanism will be using the accessors to check new and old values. Since you are changing the value within the getter, the getter will be called again, so your infinite loop begins.

    This sort of lazy loading doesn’t really work with managed objects. You can either set the activity type elsewhere, such as awakeFromFetch or when the activityTypeName is set, or if that isn’t appropriate, implement a seperate accessor:

    -(ActivityType*)calculatedActivityType
    {
        ActivityType *myType = self.activityType;
        if (myType) return myType;
    
        NSSet *types = self.myActivityTypes;
    
        NSSet *foundTypes = [types objectsPassingTest:^BOOL(id obj, BOOL *stop) {
            ActivityType *object = (ActivityType *) obj;
    
            return ([object.typeName isEqualToString:self.activityTypeName]);
    
        }];
    
        myType = [foundTypes allObjects][0];
        self.activityType = myType;
        return myType;
    }
    

    This won’t cause any loops because you’re not within any of the accessors.

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

Sidebar

Related Questions

I am having an issue in iphone when i want to use a custom
I am working on a Netty server, I am having issues with a custom
Working on a dev tracker custom PHPBB BBCode but I am having issues with
i'm having issues on my custom delegate, not sure why is not working.i wan
I'm having issues with a custom signal in a class I made. Relevant code:
I'm having issues with my SQL Reporting Services reports. I'm using a custom font
I have been having issues with a custom check box control for a while
Im having issues trying to get a custom snapin to display in the Add/Remove
I am having issues while trying to inject custom permission evaluator in spring security:
I am new to PHP and I am having issues pulling this data in..

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.