Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@property definitions with ARC: strong or retain?

Using Xcode 4.2 and ARC, I notice that the auto-generated code for an NSManagedObject still reads like this for properties:

@property (nonatomic, retain) NSString * someString; 

1) Shouldn't retain now be replace with strong or weak?

2) Why does the auto-generated code still use retain

3) What is the correct replacement for retain in this property statement?

I'm currently debugging a problem using NSFetchRequest, and I thought this might be the source of the problem. Thoughts?

like image 489
one09jason Avatar asked Oct 17 '11 16:10

one09jason


People also ask

What is strong property in objective c?

strong (default) Strong just means you have a reference to an object and you will keep that object alive. As long as you hold that reference to the object in that property, that object will not be deallocated and released back into memory.

What is difference between assign and retain?

Assign creates a reference from one object to another without increasing the source's retain count. Retain creates a reference from one object to another and increases the retain count of the source object.

What is strong attribute of property?

strong / retain : Declaring strong means that you want to “own” the object you are referencing. Any data that you assign to this property will not be destroyed as long as you or any other object points to it with a strong reference.

What is Nonatomic Objective C?

Nonatomic means multiple thread access the variable (dynamic type). Nonatomic is thread unsafe. But it is fast in performance.


1 Answers

1) Shouldn't retain now be replace with strong or weak?

No. You cannot replace retain with weak; they are different. And strong is a 100% synonym for retain; they are identical. You can use either, so there is no "should" here. You can replace retain with strong if you like, but you don't have to.

2) Why does the auto-generated code still use retain

Why not? See (1). retain is correct so there is no problem.

3) What is the correct replacement for retain in this property statement?

There is no need to replace retain.

I'm currently debugging a problem using NSFetchRequest, and I thought this might be the source of the problem. Thoughts?

It isn't.

like image 162
matt Avatar answered Sep 17 '22 15:09

matt