tags:

views:

25

answers:

1

Hi.

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

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

This has the same effect that just do:

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

Way the compiler don't complain in situations like this?

+2  A: 

Because both ways are valid.

Declaring ivar via just declaring a property for it is a new language feature available starting objc 2.0

In "Run-time differences" section of "Objective-c programming language" reference stated:

For @synthesize to work in the legacy runtime, you must either provide an instance variable with the same name and compatible type of the property or specify another existing instance variable in the @synthesize statement. With the modern runtime, if you do not provide an instance variable, the compiler adds one for you.

Vladimir
...trying to find a prooflink meanwhile :)
Vladimir
See e.g. [here](http://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html#//apple_ref/doc/uid/TP30001163-CH17-SW9) ... *"For the modern runtimes [...], instance variables are synthesized as needed. If an instance variable of the same name already exists, it is used."*
Georg Fritzsche
Thanks for your answers.
GojaN