• 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
Core Data, NSURLProtocol and Threads - A Case of Missing Managed Objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Core Data, NSURLProtocol and Threads - A Case of Missing Managed Objects


  • Subject: Core Data, NSURLProtocol and Threads - A Case of Missing Managed Objects
  • From: Philip Dow <email@hidden>
  • Date: Tue, 5 Feb 2008 16:25:23 -0800

Hi all,

I have a complex situation that I'll try to explain correctly. I'm using my own url protocol to load image data from an in memory store into a webkit web view. When an image is dropped onto the web view I intercept it, grab the tiff data, write the data to a new managed object and substitue my own html string with the correct img src information.

Almost instantaneously the webview informs its delegate that it has received a url request. I substitute my own url request and in the url protocol subclass ensure that it will have the responsibility for loading it. It does, and the url protocol subclass calls back to the document object to grab the image data using a special identifier I am encoding in my own url.

That callback happens on a separate thread, so I create a second manage object context from the document's persistent store and use a fetch with a predicate attached to grab the sought image data's managed object -- the fetch request uses the unique id encoded into the url, which the protocol subclass is passing in the callback. If I find the object, I grab the image data from it and return that back to the protocol subclass.

It's hard to believe this is all possible, but sure enough! Everything works but with a caveat. In the second thread as the url protocol is loading and calling back to the document to grab the image data, my fetch request on the second object context does not return the object until I actually save the document.

This means that immediately after the drop, the fetch doesn't see the object I just created in the first context, but as soon as I save the document and reload the webview, it does. Reloading the web view without saving the context does not suffice.

I've tried calling commitEditing, processPendingChanges and refreshObject:mergeChanges on the two contexts but nothing seems to work. How can I ensure that the second context on the second thread sees the object just created by the first context in the first thread?

Thanks,
~Phil



_______________________________________________

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: Core Data, NSURLProtocol and Threads - A Case of Missing Managed Objects
      • From: Mike Abdullah <email@hidden>
  • Prev by Date: Re: [[NSView animator] setHidden:YES] doesn't fade?
  • Next by Date: Core Data, NSURLProtocol and Threads - A Case of Missing Managed Objects
  • Previous by thread: Re: [[NSView animator] setHidden:YES] doesn't fade?
  • Next by thread: Re: Core Data, NSURLProtocol and Threads - A Case of Missing Managed Objects
  • Index(es):
    • Date
    • Thread