2

What's the difference between putting a variable inside of the @interface{} declaration in a header file, and putting in a @property after that declaration?

E.g.,

@interface GameCenterManager : NSObject
{
GKInvite* pendingInvite;
}
@end

as opposed to

@interface GameCenterManager : NSObject
@property (weak, nonatomic) GKInvite* pendingInvite
@end
1

1 Answer 1

3

Declaring a property generates getters and setters for the instance variable, according to the criteria within the parenthesis.

Defining the variables in the brackets simply declares them instance variables.

Following are some links that provides more info on these.

http://www.cocoawithlove.com/2010/03/dynamic-ivars-solving-fragile-base.html

Is there a difference between an "instance variable" and a "property" in Objective-c?

http://iphonedevelopment.blogspot.in/2008/12/outlets-property-vs-instance-variable.html

Sign up to request clarification or add additional context in comments.

7 Comments

Not sure, but to generate the getter and setter you must synthesize no?
@PatricioIgnacioFariaValdivi Not anymore. Just @property is enough, it'll create an iVar automatically with a underscore prefix. You can test this with @property (nonatomic) NSString *foo in interface, without synthesize you can get _foo in you implementation.
@PatricioIgnacioFariaValdivi You need not synthesize from ios6 as it is synthesized automatically by the system. where as previous versions need you to synthesize manually,
Awesome, good to know, thanks. But well, if he is using and iOS < 6 he must synthesize :)
@PatricioIgnacioFariaValdivi yes exactly! :)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.