Why are Objective-C properties uncomfortable?

This is more of a complaint than a question, although perhaps someone has some good points. So, basically, if you want ivar in your Objective-C class to have helper methods, you should mention it 3 times

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

and possibly the 4th time in the dealloc method. So it would not be more convenient if this approach was similar to 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 access methods, and dealloc to release the ivar in the dealloc method.

+3
source share
2 answers

ivar - , . iVar : ( - , , )

@interface MyClass : NSObject 
{
}

@property(copy) NSString *name;

@end

...
@synthesize name;

XCode (, 4.0) @synthesize - .

, , objective-c , :)

+6

Xcode 4, , . ARC ( ) dealloc .

0

Source: https://habr.com/ru/post/1756527/


All Articles