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?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- back button text does not change
- iOS (objective-c) compression_decode_buffer() retu
- how to find the index position of the ARRAY Where
相关文章
- 现在使用swift开发ios应用好还是swift?
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- didBeginContact:(SKPhysicsContact *)contact not in
- Custom Marker performance iOS, crash with result “
Copying and ARC are orthogonal: you make copies of mutable objects to "freeze" their state; ARC keeps track of object's reference count.
NSString
objects may or may not be mutable. When you receive anNSString*
as a parameter, you cannot be certain that it is immutable unless you check its type (and even then you may get false positives). If your algorithm relies on the string not changing after being set, making a copy is the right thing to do. ARC, on the other hand, will ensure that the object is not released while you are holding a strong reference to it.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.
copy
counts asstrong
. Use:https://devforums.apple.com/message/654033#654033
or even:
http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/ProgrammingWithObjectiveC/DefiningClasses/DefiningClasses.html#//apple_ref/doc/uid/TP40011210-CH3-SW7
It doesn't matter if you're using ARC or non-ARC.
The reasoning behind the
copy
is so that you can guarantee that your class' internal state can't be modified from outside the implementation.This could happen if someone passes you an
NSMutableString
, and then modifies it later. That consideration is independent of the memory management environment.