views:

65

answers:

1

It is more of a complain than a question, though maybe someone has some good points on it. So basically if you want an ivar in your Objective-C class have accessor-methods you have to mention it 3 times

SomeClass* _ivar;
@property (nonatomic,retain/assign/copy) SomeClass* ivar;
@synthesize ivar = _ivar;

and maybe 4th time in dealloc method. So wouldn't it be more convenient if the approach would be like Java-style annotations - in one place before the actual ivar declaration, just something like:

@property (nonatomic,retain,synthesize = ivar,dealloc) SomeClass* _ivar; 

this also generates accessor methods, and dealloc - telling to dealloc the ivar in dealloc method.

+3  A: 

Actually you don't have to declare ivar - they can be synthesized if you just declare property for them. This should synthesize name iVar for you: (not supported in legacy run-times though - so one of the reasons of this seemingly redundant syntax is for backward compatibility with legacy platforms)

@interface MyClass : NSObject 
{
}

@property(copy) NSString *name;

@end

...
@synthesize name;

In new XCode version (4.0 probably) you won't need to use @synthesize as well - properties will be synthesized by default.

So as you see objective-c develops to satisfy your wishes :)

Vladimir
Ha, thanks, nice to know :) I will check this.
justadreamer