0

I'm new to core data and objective-c in general. In NSManagedObjectContext's documentation, in the reset method, it is stated that:

If you use this method, you should ensure that you also discard references to any managed objects fetched using the receiver, since they will be invalid afterwards.

however I really could't figure this out - what does "discard reference to to any managed objects fetched" means and how do I do it? By the way, I am asking this question because I have to debug some code in an app which crashes when calling the reset method.

I tried looking for answers, and found this question on Stack Overflow, but couldn't really figure out the answer.

If you have any idea what does discarding reference to fetched managed objects mean and / or how to do it, it will be very appreciated.

1 Answer 1

0

In today's ARC world, it means that you shouldn't hold any non-zeroing references. Both strong references and properties with the assign attribute qualify.

It's generally not a good idea to pass managed objects around, as there are issues with regards to threading and proper contexts. It's usually better to pass the objectID and let the callee fetch the object into an appropriate context. If you're doing that, you should have few problems.

P.S. You can pass objects around if their context is long-lived and you use the performBlock: and performBlockAndWait: APIs. If you're doing this, you may run into problems holding references to objects that become invalid.

Not the answer you're looking for? Browse other questions tagged or ask your own question.