What's the typical use-case of the copy
properties' attribute?
When should I copy some value instead of just incrementing reference count as it can be achieved via the strong
property?
What's the typical use-case of the copy
properties' attribute?
When should I copy some value instead of just incrementing reference count as it can be achieved via the strong
property?
Others have answered this before, so I'll just point you to a couple of them.
First, the Apple docs: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html, search for "Copy Properties Maintain Their Own Copies"
Here is a pretty good explanation of the various property attributes: Objective-C declared @property attributes (nonatomic, copy, strong, weak)
This answer does a good job of explaining a pretty typical use case and why you'd use copy: NSMutableString as retain/copy
Neither, however, mentions block properties, and you never want to use anything other than copy
for blocks (assuming, of course, that you're using ARC, and ARC even handles this for you automatically):
Note: You should specify copy as the property attribute, because a block needs to be copied to keep track of its captured state outside of the original scope. This isn’t something you need to worry about when using Automatic Reference Counting, as it will happen automatically, but it’s best practice for the property attribute to show the resultant behavior. For more information, see Blocks Programming Topics.