• 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: Relationships during awakeFromInsert
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re: Relationships during awakeFromInsert


  • Subject: re: Relationships during awakeFromInsert
  • From: Ben Trumbull <email@hidden>
  • Date: Sat, 2 Feb 2008 00:11:04 -0800

In my Core Data Document based application, I need to initialize some
attributes in instances one class (MOB) using attributes from another
class (MOA, which is the root object of the document) to which the first is related. Here is what the classes each look like:


	MOA
	_____
	aTitle - string
	seed - double
	myMOBs - one-to-many relationship to MOB


MOB _____ bTitle - string seeded - double myMOA - many-to-one relationship to MOA


In MOB's awakeFromInsert I have the following:

	- (void)awakeFromInsert
	{
		[super awakeFromInsert];

		MOA* anMOA = self.myMOA;
		self.seeded = anMOA.seed;
	}

What I'm seeing is that self.myMOA is 'nil' in this awakeFromInsert, so apparently the relationship has not yet been established.

MOB just got allocated. The -initWithEntity... method is usually still on the stack frame. It doesn't have a .myMOA yet. It's not clear from your description why one would expect otherwise.


I've tried intercepting setValue:forKey: and setPrimitiveValue:forKey: but
they don't appear to be called during creation of an MOB.

self.seeded = foo;

is

[self setSeeded:foo];

not

[self setValue:foo forKey:@"seeded"];


Where can I set MOB's 'seeded' using MOA's 'seed'?

Presumably you have some code somewhere that does something like:
NSManagedObject* MOB = [NSEntityDescription insertNewObjectForEntityForName:@"MOB" inManagedObjectContext:moc];


Right after that would work.

If you have a reference to MOA during -awakeFromInsert (like in a global, or through the appDelegate), and doing things the easy way doesn't work, you could do something like -performSelector:... afterDelay:0 or in response to the MOC's NSManagedObjectContextObjectsDidChangeNotification.

--

-Ben
_______________________________________________

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


  • Follow-Ups:
    • Re: Relationships during awakeFromInsert
      • From: Mike Rossetti <email@hidden>
  • Prev by Date: NSAppleScript question
  • Next by Date: Re: NSAppleScript question
  • Previous by thread: Relationships during awakeFromInsert
  • Next by thread: Re: Relationships during awakeFromInsert
  • Index(es):
    • Date
    • Thread