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

  • Home
  • SEARCH
  • 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 7918617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:34:13+00:00 2026-06-03T15:34:13+00:00

I have an NSManagedObject that has an attribute that I use only for ordering

  • 0

I have an NSManagedObject that has an attribute that I use only for ordering in an NSFetchedResultsController. The value of that attribute is determined from the values of other attributes or relationships.

Therefore I figure out its value when I am getting ready to save the object. It seems, from my reading of documentation and experimenting, that I can do this in either - (void) willSave or - (BOOL) validateForUpdate: NSError **error.

My experimenting shows me these are called in tandem, first validateForUpdate then willSave.

However, since my insight into what is happening behind the scenes is poor, I was wondering it anyone could advise if one place is better than the other to set the value and why?

Thanks.

  • 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-03T15:34:14+00:00Added an answer on June 3, 2026 at 3:34 pm

    if you have a derived value, you typically do not want to save it, but if you do want to save it (thus negating the advantage of dynamically generating it, but can be done for speed reasons if you have a lot of objects and want to do some fancy predicate work.) you can set it up in your model as a normal value then make a custom accessor that checks to see if the primitive value is set, with primitiveValueForKey:@"propertyName"… something like

    .h 
    @property()NSString* someProperty;
    
    .m
    @dynamic someProperty;
    -(NSString *) someProperty
    {
        pValue = [self primitiveValueForKey;@"someProperty"];
        if(!pValue)
        {
             //calculate pvalue
             pValue = [self derivedPValue];
             [self setPrimitiveValue: pValue forKey:@"someProperty"];
        }
     return pValue;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CoreData NSManagedObject subclass, TextNarration, that has an attribute of type NSString,
i have an NSManagedObject that has just attributes(no fetched properties or relationshiops). I retain
I have an object NetworkMember that has no attributes but is defined by its
I have an NSManagedObject that has a to-many relationship to another NSManagedObject. During creation
I have a subclassed NSManagedObject that conforms to the MKAnnotation protocol and it has
So my problem is that I have a NSManagedObject 'A' which has a has-many
I have a ConfiguracaoDaApp class in my project that is a NSManagedObject subclass. I
I have an NSManagedObject who has a one to many relationship with the parent
I have some NSManagedObject classes created for use with CoreData I need to add
How can I copy an NSManagedObject from one NSManagedObjectContext to another? I have 2

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.