Method Names and Non-ARC Compiled Code

ARC works with code that has not been compiled with ARC.This can happen if you’relinking with an older framework, for example. As long as the non-ARC code has con-formed to the standard Cocoa naming conventions, all will be okay.That is, when ARCsees a method call, it checks the method’s name. If the name begins with the wordsalloc, new, copy, mutableCopy, or init, it assumes that the method returns ownership ofthe object back to the method caller.

When we talk about “words” here, we refer to the words being written in what’sknown as camelCase.That’s where the first letter of each new word in the name beginswith a capital letter. So the compiler assumes methods named allocFraction,newAddressCard, and initWithWidth:andHeight: returns ownership of the objects,whereas newlyWeds, copycat, and initials, do not. Again, this happens automaticallywith ARC, so you don’t need to worry about this, unless you’re using methods that don’tfollow these standard naming conventions. In those cases, there are ways to explicitly tellthe compiler whether a method returns ownership of an object despite its name.

Note that the compiler gives you an error if you try to synthesize properties whosenames begin with any of the special words mentioned in the first paragraph of this sec-tion. 

你可能感兴趣的:(properties,cocoa,object,each,compiler,methods)