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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:55:25+00:00 2026-06-08T02:55:25+00:00

I have an NSManagedObject class with a updatedOn attribute. I was hoping to implement

  • 0

I have an NSManagedObject class with a updatedOn attribute. I was hoping to implement the logic to set its value in the class’s willSave method. When I tried to do this, I found that willSave was never being called on my instances of this class.

After some investigation, I determined that the willSave method was not being called for newly created instances, where updatedOn was not initialized to any value. Because this attribute was not set to be optional, the validation fails and apparently the willSave method only gets called if the instance is valid.

My question is this: Is there a best practice for doing this kind of thing? Do I need to make the updatedOn attribute optional to work around this? Or should I implement the awakeFromInsert method of my class to set an initial value there, and then overwrite that value when the willSave method eventually gets called? Or is there some simpler approach that makes more sense?

  • 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-08T02:55:26+00:00Added an answer on June 8, 2026 at 2:55 am

    The willSave documentation makes reference to using the method for time stamping and despite mentioning some complications around changing property values and recursion, it doesn’t warn specifically against this use. So I guess, based on that fact, it could be considered a reasonable place to put this functionality.

    The documentation does, however, refer to the use of the NSManagedObjectContextWillSaveNotification for calculating a common timestamp, so perhaps this would be a alternative location for this work. It would require manual inspection of the insertedObjects and updatedObjects collections on the managedObjectContext to locate the objects that need time stamping, but based on some quick tests it does seem to be called before the validation steps so you would have an opportunity to set the required property here.

    If you chose to stick with willSave then I guess you have 3 options.

    • A required property with a specified default value in your model.
    • A required property with the property set on awakeFromInsert or some other suitable point.
    • An optional property.

    I think any of the options are reasonable choices, but I think if it were me I would probably chose the NSManagedObjectContextWillSaveNotification just because of the complications with setting property values in willSave.

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

Sidebar

Related Questions

I have a Data class that subclasses NSManagedObject with a single bool property attribute.
I have a NSManagedObject subclass, created by the XCode model interface. This class has
So I have this class: @interface AmountViewController : UITableViewController <UITableViewDelegate, UITextFieldDelegate>{ NSManagedObjectContext *managedObjectContext; NSManagedObject
I have a ConfiguracaoDaApp class in my project that is a NSManagedObject subclass. I
I have method that returned NSManagedObject and I don't know what kind of NSManagedObject
I have the following class definition. Contact.h #import <CoreData/CoreData.h> @interface Contact : NSManagedObject {
In my Objective-C project I have a Country class (NSManagedObject subclass). When comparing a
I have a CoreData NSManagedObject subclass, TextNarration, that has an attribute of type NSString,
My problem is similar to: Problem creating NSManagedObject derived class I have setup a
I have an entity class called catObras, and it inherits from the class NSManagedObject.

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.