tags:

views:

1839

answers:

3

I'm trying to find documentation on how I can override a property name in Objective-C with @synthesize. If I have an instance variable name of 'foo', I want to write it's accessor as 'bar'.

Doing something such as

@synthesize foo = bar;

gives a compile-time error.

+3  A: 

You can but "bar" has to exist first (be a declared variable). From the documentation

You can use the form property=ivar to indicate that a particular instance variable should be used for the property, for example:

@synthesize firstName, lastName, age = yearsOld;
KiwiBastard
In the OP's example, the correct form would be @synthesize bar = foo; since he says foo is his ivar and he wants to access it with bar.
mahboudz
+5  A: 

You can change the getter name when you declare the property (getter=bar).

PEZ
+11  A: 

I think you just have it backwards in your @synthesize. What you want is:

@synthesize bar = foo;
Kelan