Properties and instance variable declaration

I notice that you can "declare" a variable in this way:

@interface A {
    NSString *instanceVariable;
}
@property (nonatomic, retain) NSString *instanceVariable;
@end

This has the same effect as just:

@interface A {
}
@property (nonatomic, retain) NSString *instanceVariable;
@end

Why does the compiler not complain in such situations?

+3
source share
1 answer

Because both ways are valid.

Declaring ivar by simply declaring a property for it is a new language feature available since objc 2.0

In the "Run-time difference" in the "Objective-c programming language" section:

@synthesize , @synthesize. , , .

+7

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


All Articles