Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should an NSString property under ARC be strong or copy?

When not compiling with ARC, it is recommended to use copy properties for data types such as NSString. I could not find proper documentation on the use of copy in ARC mode. Can someone tell me what's applicable for ARC?

like image 237
rustylepord Avatar asked Jun 28 '12 17:06

rustylepord


People also ask

What is the 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 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.


1 Answers

It is still recommended to copy because you want to avoid something passing a mutable string and then changing it without you knowing. A copy guarantees that the string you have will not change.

like image 148
Joe Avatar answered Oct 02 '22 09:10

Joe