问题
Is there some of documentation how the compiler auto-generates the accessors of properties?
When writing custom accessors (overriding the synthesized ones), it would be nice to know the original implementation. Especially to see the differing implementations of accessors for properties with different (weak/strong/retain/copy etc..) attributes.
回答1:
Is there some of documentation how the compiler auto-generates the accessors of properties?
The compiler just adds a C function call. Peek at the asm (e.g. _objc_getProperty
and _objc_setProperty
).
When writing custom accessors (overriding the synthesized ones), it would be nice to know the original implementation. Especially to see the differing implementations of accessors for properties with different (weak/strong/retain/copy etc..) attributes.
The implementations are publicly available as part of the objc runtime hosted at http://www.opensource.apple.com/source/objc4/.
来源:https://stackoverflow.com/questions/10129203/accessor-implementation-of-properties