Re: Synthesized instance variables
Re: Synthesized instance variables
- Subject: Re: Synthesized instance variables
- From: Frank Illenberger <email@hidden>
- Date: Thu, 12 Mar 2009 18:58:15 +0100
I second Andreas. For most cases, the correct place to declare
instance variables should be the .m file as they are an
implementation detail and not part of the contract with the outside
world using the class. The feature of non-fragile instance
variables of the modern ABI should make this dream possible.
Synthesizing already takes place on the .m side but I also do not
know how to gain access to the actual synthesized instance variable
in a custom getter. Using objc_getInstanceVariable is not a good
alternative as it is far to slow for being used in an on-demand
getter. I think, Andreas does not care whether it is theoretically
possible for the outside world to access the memory of his instance
variables. He merely does not want to cite them is the contract.
The Objective-C release notes mention the symbol format OBJC_IVAR_
$_ClassName.IvarName for ivars but the compiler does not seem to
understand it.
Does anybody know a way to access synthesized instance variables
without using the synthesized getter methods?
You can't in the current compiler. A future compiler should fix
that. Use explicit @private ivars in the meantime. An @private ivar
should not be considered part of the contract - that's what @private
means, enforced by compiler warnings and linker errors.
And why isn't there a way to explicitly declare instance variables
in the .m file for the new runtime?
Three reasons: (1) there are some non-trivial design details to work
out, (2) compiler-engineer-hours are limited, and (3) @private ivars
are generally good enough.
Thanks for clarifying this. So I am looking forward to that new
compiler, as I think, moving private ivars to the @implementation side
will greatly enhance the conciseness of the @interface side.
Cheers
Frank
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden