Variables inside the {} parenthesis are instance variables. They're accessible only to the class.
@property defines a few different things denoted by the (options).
Most people use @property to convenience methods inside your .m and .h files. For example
@property (strong) NSString *string;
Creates two methods inside your .h and .m file, invisible to you though, called:
-(NSString *)string; //returns the string object
-(void)setString:(NSString *)string;
So what it does is improve readability and helps reduce a lot of boiler plate code.
It's no longer necessary to define the instance variable inside the {} parenthesis now.
If you need to have the instance variable set to a different name you can put a
@synthesize string = _string;
Since you're new at this Ill add some bonus stuff for you to think about.
self.string = @"string"
May not be an equivalent call as
string = @"string"
If you have @property (strong) NSString *string; and @synthesize string;
The reason for this is setting the string via self.string is using the method implementation to set the string and may be overridden like this:
-(void)setString:(NSString *)str{
string = [NSString stringWithFormat:@"%@.jpg", str];
}
So self.string = @"hello" would be @"hello.jpg" where as string = @"hello" is just "hello"
Also self.string = @"string"; is much the same as [self setString:@"string"];
For clarification on what @property(strong)NSString *string does
inside the .h adds:
{
NSString *_string;
}
-(void)setString:(NSString *)string;
-(NSString *)string;
inside .m:
-(void)setString:(NSString *)string{
_string = string;
}
-(NSString *)string{
return _string;
}
So there's no need to call @synthesize unless you want to rename the iVar into something else
@synthesize string = wibblyWobblyTimeyWimey;
so in the .h it would be
{
NSString *wibblyWobblyTimeyWimey;
}
inside the .m
-(void)setString:(NSString *)string{
wibblyWobblyTimeyWimey = string;
}
-(NSString *)string {
return wibblyWobblyTimeyWimey;
}