On Apr 11, 2008, at 2:37 AM, Thomas T wrote:

- How can I create objects in my nsoperation when I don't have a
persistent store yet. I really couldn't ask the user to save the
document before beginning the download.
- In document based apps - how should I create my second
NSManagedObject context for use in my nsoperation?

Unfortunately, the only option I can think of is that you're going to have to use performSelector:onMainThread: to actually do the inserts and updates on the main thread, perhaps caching data and only passing it periodically to the main thread. You'll have to be careful, as this could potentially push a lot of work onto your main thread and result in the Spinning Beachball of Death if you're not careful. I would suggest opening an enhancement request using Apple's Bug Reporter. This is clearly a design issue that is going to affect more and more people as time goes by and more projects adopt Core Data. Apple is not likely to change it unless they hear from us that we're unhappy with it.

Another option would be to use callbacks instead of synchronous communications in a thread, which would put your code to download the data on the main thread. I've done this in a Core Data (non document- based) app that I'm working on. It adds some complexity to the code, but it works. I'll admit that it was a lot of work getting it to perform well, though. My original code created a lot of NSManagedObjects in the callback, and that was causing the Spinning Beach Ball of Death to come up and make the app basically unusable during the download. I had to switch to basically storing all the downloaded data as an NSArray of non-managed objects, and then storing the array as a single custom attribute. It was less than ideal - worked out well in that case because I didn't really need managed objects for all the downloaded data, but I can imagine many cases where that wouldn't have been an option.

Jeff

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to