• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSManagedObject Initialization Methods Not Called
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSManagedObject Initialization Methods Not Called


  • Subject: Re: NSManagedObject Initialization Methods Not Called
  • From: Richard Somers <email@hidden>
  • Date: Tue, 22 Sep 2009 16:14:34 -0600

On Sep 21, 2009, at 4:04 PM, Mike Abdullah wrote:

More information please. What store type are you using?

On 21 Sep 2009, at 20:12, Richard Somers wrote:

I have a core data document based application. When a file on the disk is opened -awakeFromInsert and -awakeFromFetch are never called for one of my NSManagedObject objects.

Why is not one of these methods getting called when the object is loaded into memory from disk?


Here is a distilled version of my code. The actual code is a little more involved than this but not by much. The code works very well except for the life cycle methods of NSManagedObject.

// The Xcode data model has 3 entities: Parent, Child1, and Child2. There are
// no relationships.


// The Parent class has no properties or methods. It provides a root class
// which can be iterated to access all children.


@interface Parent : NSManagedObject
@end

@implementation Parent
@end

// Child1 has no properties but does have ivars.

@interface Child1 : Parent
{
     ivar1;
     ivar2;
}
@end

@implementation Child1
- (void)awakeFromInsert
{
     [super awakeFromInsert];
     // Initialization ...
}
- (void)awakeFromFetch
{
     [super awakeFromFetch];
     // Initialization ...
}
- (void)didTurnIntoFault
{
     // Cleanup ...
}
@end

// Child2 has properties but no ivars.

@interface Child2 : Parent
@property (retain) NSNumber *attribute1;
@property (retain) NSNumber *attribute2;
@end

@implementation Child2
@dynamic attribute1;
@dynamic attribute2;
- (void)awakeFromInsert
{
     [super awakeFromInsert];
     // Initialization ...
}
- (void)awakeFromFetch
{
     [super awakeFromFetch];
     // Initialization ...
}
- (void)didTurnIntoFault
{
     // Cleanup ...
}

// End of code

Results of various actions.

Child1 or Child2 object with in memory store
     Action          Life Cycle Result
     Add Object      awakeFromInsert (correct)
     Remove Object   didTurnIntoFault (correct)

Child1 object with xml, SQLite, or binary on disk store
     Action          Life Cycle Result
     Open File       nothing (should be awakeFromFetch)
     Remove Object   awakeFromFetch (should be didTurnIntoFault)

Child2 object with xml, SQLite, or binary on disk store
     Action          Life Cycle Result
     Open File       awakeFromFetch (correct)
     Remove Object   nothing (should be didTurnIntoFault)

As you can see sometimes the corect life cycle method is called and sometimes not. Any insight or comments on what might be the problem would be appreciated.

Richard

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NSManagedObject Initialization Methods Not Called (From: Richard Somers <email@hidden>)
 >Re: NSManagedObject Initialization Methods Not Called (From: Mike Abdullah <email@hidden>)

  • Prev by Date: Re: FileManager Problem Post OS X 10.6 Installation
  • Next by Date: Re: an app that never quits
  • Previous by thread: Re: NSManagedObject Initialization Methods Not Called
  • Next by thread: Re: NSManagedObject Initialization Methods Not Called
  • Index(es):
    • Date
    • Thread