• 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: Calling processPendingChanges from awakeFromInsert
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling processPendingChanges from awakeFromInsert


  • Subject: Re: Calling processPendingChanges from awakeFromInsert
  • From: Jim Correia <email@hidden>
  • Date: Fri, 21 Sep 2007 08:09:24 -0400

On Sep 20, 2007, at 6:32 PM, Mike Burns wrote:

You make some good points there, and after reevaluating my code I can see how getting rid of that project relationship would make more sense for my purposes. (I have other managed objects like the WBObject with that same relationship and the same goes for them.) But in the interest of figuring out what isn't working, I remember why I asked that question in the first place. The following code creates the same problem that "processPendingChanges" seemed to cause in the first place (duplicating the newly created object):

[...]

Does executing a fetch request cause that same problem?

You previously discovered that -processPendingChanges inside of - awakeFromInsert was problematic. Turns out that fetching is problematic for the same reason; Core Data does equivalent work to - processPendingChanges right before doing a fetch.


The documentation indirectly tells us that you shouldn't fetch from inside -awakeFromInsert. It says

<http://developer.apple.com/documentation/Cocoa/Reference/ CoreDataFramework/Classes/NSManagedObject_Class/Reference/ Reference.html>

	Methods to Override Considerations

	The following methods are intended to be fine grained and not perform
	large scale operations. You must not fetch or save in these methods. In
	particular, they should not have side effects on the managed object
	context:

		•	initWithEntity:insertIntoManagedObjectContext:
		•	didTurnIntoFault
		•	dealloc

-awakeFromInsert is not in the list, but you can infer that it is disallowed since it happens from within one of the disallowed methods.

And if so, what is the best work around?

Whichever one fits in best with your code, and doesn't require a fetch to be executed as part of object insertion.


You can prefetch and store the Project when you setup your document, or fetch it on demand before inserting the object. Your custom subclass of NSManagedObject can have a convenience method

+ (id)insertNewWBObjectWithProject:(NSManagedObject *)project InManagedObjectContext:(NSManagedObjectContext *)context;

To make this easier. Remember, just because there is an -insert: action method on the array controller doesn't mean you have to use it. Often it is appropriate to have the target of your button be your own action method where you write custom code to insert the object.

Jim_______________________________________________

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: 
 >Calling processPendingChanges from awakeFromInsert (From: Michael Burns <email@hidden>)
 >Re: Calling processPendingChanges from awakeFromInsert (From: Jim Correia <email@hidden>)
 >Re: Calling processPendingChanges from awakeFromInsert (From: Michael Burns <email@hidden>)
 >Re: Calling processPendingChanges from awakeFromInsert (From: Jim Correia <email@hidden>)
 >Re: Calling processPendingChanges from awakeFromInsert (From: Mike Burns <email@hidden>)
 >Re: Calling processPendingChanges from awakeFromInsert (From: Jim Correia <email@hidden>)
 >Re: Calling processPendingChanges from awakeFromInsert (From: Mike Burns <email@hidden>)

  • Prev by Date: Re: new class
  • Next by Date: Re: Core Data guidance Was: Calling processPendingChanges from awakeFromInsert
  • Previous by thread: Re: Calling processPendingChanges from awakeFromInsert
  • Next by thread: Re: Calling processPendingChanges from awakeFromInsert
  • Index(es):
    • Date
    • Thread