I am trying to convert non-ARC project to use ARC but for some reason its complaining about the use of all instance variables.
@property (nonatomic,retain)id myvariable;
results in
Error : "Use of undeclared variable _myvariable"
there are some places in my code where I don't want to modify retain count but do an assignment to the property. so I use an instance variable.
adding @syhtnesize myvariable =_myvariable
resolves this problem but I am trying to figure out the right way to fix this.
Possible solutions:
1) Add synthesize
2) replace use of instance variable with self.myvariable
and make property assigned.
EDIT: Extension of problem ARC errors
It depends what you need. If you declare property:
And you want to change name of the private ivar to something different that _myvariable you have to add
@synthesize myvariable = _myVarNewName
but if you want to use exactly the same name with underscore on the front just remove @synthesize (works with iOS 6 and above) and the compiler do the rest so you can access the private variable like _myvariable or public like self.myvariable.
With all the arc stuff
is accessible by both
and
No need to use @synthesize
It sounds like you've hit a backward compatibility feature.
Since Xcode 4.4 property declarations no longer require an
@synthesize
statement and without one the compiler auto-generates an_propertyName
instance variable.However with an
@synthesize propertyName
, as you would pre-Xcode 4.4, then the compiler will auto-generate anpropertyName
- note no underscore - instance variable.The compiler messages warning you "Use of undeclared variable _myvariable" suggest you have switched the code to use underscores but still have some
@synthesize myvariable
statements.Your use of
@synthesize myvariable = _myvariable
specifies the name to use for the instance variable directly, and so solves your problem, but removing the@synthesize
completely is the usual approach.