0

I have an issue where I have a NSOperation running in a background thread, and in the execution loop of that execution i call performSelectorOnMainThread to execute a NSURLRequest, But the main thread never gets the call to execute that NSURLRequest.

The purpose of the nsoperation is to build a json string from a core data entity which could take quite some time due to it being a large object. I have ensured core data thread safety by passing only the reference of the managed object's ID and using a different managed object context, so no need to worry about that.

Any advice will be appreciated.

stephen
  • 1,617
  • 3
  • 20
  • 27

1 Answers1

0

Make sure that your NSOperation init function is not using objects from the wrong thread, that has tripped me up before with Core Data. If I recall, the init function was called on the main thread, so when I initialized my object context there and tried to access it in main() it crashed the background thread. It can help debugging to look at what thread parts of your code are running in by printing the current thread ID.

Community
  • 1
  • 1
Nicolas Renold
  • 557
  • 2
  • 5
  • No problems here as i'm only passing in an managedobjectID in the init and perform the fetch from the background thread using a different managed object context. The other thing that's passed in is a delegate. – stephen Jun 08 '12 at 00:39
  • Then I would try checking that the delegate object is still around, and maybe try an alternate way of calling your selector on the main thread such as dispatch_async() – Nicolas Renold Jun 08 '12 at 01:22