zs2020
zs2020

Reputation: 54532

Why I need to retain the managed object in order to process?

Here is what was going on in my code. I have a class B which contains a method retuning the fetched result R whose type is NSManagedObject to my current class A. And I assign the R to the the property pR in A. After a while another method in A tried to update the object MO and persistent it in database. However pA became nil at that time. I needed to retain the R when it was assigned to pR. I declared pR to be (nonatomic, retain) and synthesized it. Does the fetched result returned from B will be released automatically?

Upvotes: 0

Views: 130

Answers (1)

RunLoop
RunLoop

Reputation: 20376

Are you using the format:

self.pR = R;

if you only say pR = R;, R will not be retained as you are not accessing the synthesized method.

Upvotes: 1

Related Questions