In my working with this, I've noticed the following behavior.
- If you have a readwrite property, don't have a
@synthesize
, have a getter and don't have a setter, then it will generate the iVar.
- If you have a readwrite property, don't have a
@synthesize
, don't have a getter, and have a setter, then it will generate the iVar.
- If you have a readwrite property, don't have a
@synthesize
and have both a getter and a setter, then it will not generate the iVar.
- If you have a readonly property, don't have a
@synthesize
and don't have a getter, then it will generate the iVar.
- If you have a readonly property, don't have a
@synthesize
and have a getter, then it will not generate the iVar.
From this, I think the general rule is that if you don't have a @synthesize
, and have all the methods needed to fully implement the property, then it's assumed to be dynamic and doesn't generate the iVar.
At any rate, if you want to ensure that an iVar is not generated then declare it as @dynamic
.
Clarification on @dynamic
From Declared Properties in The Objective-C Programming Language:
You use the @dynamic keyword to tell the compiler that you will fulfill the API contract implied by a property either by providing method implementations directly or at runtime using other mechanisms such as dynamic loading of code or dynamic method resolution.
To me this reads like it OK to mark a property as @dynamic even when you are directly implementing the getter and setter.
@synthesize
is to create the iVars for you. – Contextual