3

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.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
bijan
  • 1,675
  • 18
  • 30
  • 1
    possible duplicate of [What equivalent code is synthesized for a declared property?](http://stackoverflow.com/questions/5350563/what-equivalent-code-is-synthesized-for-a-declared-property) – jscs Apr 12 '12 at 19:03

1 Answers1

3

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/.

justin
  • 104,054
  • 14
  • 179
  • 226
  • Would you be so nice to tell me where to find it in the public? – bijan Apr 12 '12 at 19:02
  • this is the current version http://www.opensource.apple.com/source/objc4/objc4-493.11/runtime/Accessors.subproj/objc-accessors.m – justin Apr 12 '12 at 19:05
  • is the retain/release stuff still required, when using ARC? – bijan Apr 12 '12 at 19:12
  • 1
    @bijan i'm not sure what exactly you are asking me. if it helps: ARC still uses reference counting - it's just *largely* abstracted from you. if you use a primitive such as `objc_setProperty`, then yes, you would need to pass the correct parameter values in order for the reference counts (as well as behavior) to be correct for the declared property. – justin Apr 12 '12 at 19:25
  • i meant, when implementing my own accessors, do i still have to do MRC? When for example implementing a setter for a (retain) property: Do i still have to release the old value and retain the new one, or does ARC do that for me? – bijan Apr 12 '12 at 19:34
  • @bijan by default, ARC handles that for you. the docs detail this better than i can in comment fields. – justin Apr 12 '12 at 21:03
  • yeah you're right, i'll check the docs. thank you anyway, the link was very helpful! – bijan Apr 12 '12 at 21:18