I am listening/watching the tutorial on Paul Hegarty from the App Store. In his lesson he states that you should ALWAYS synthesize your properties on the implementation file like so:
@sysnthesize example = _example;
I am also doing a apple documentation tutorial that does not synthesize properties. It also has init methods like so:
- (id)initWithName:(NSString *)name location:(NSString *)location date:(NSDate *)date
{
self = [super init];
if (self)
{
_name = name;
_location = location;
_date = date;
return self;
}
return nil;
}
@end
Will these to interact, cancel or otherwise mess with each other if add them together like so:
@implementation BirdSighting
@synthesize name = _name;
@synthesize location = _location;
@synthesize date = _date;
- (id)initWithName:(NSString *)name location:(NSString *)location date:(NSDate *)date
{
self = [super init];
if (self)
{
_name = name;
_location = location;
_date = date;
return self;
}
return nil;
}
@end
Thanks for the help.
Thinking of it in terms of “will these interact” is perhaps not the right mental model. The place to start is understanding what each of those lines does. So let’s consider one from each example:
If a property (@property, usually in the .h) called name exists, then this does a few things:
Now the other example:
This does one thing; it assigns the address of ‘name’ to the instance variable _name.
So now that we understand what those do, let’s consider how they interact:
One additional consideration:
In very recent versions of Xcode, the compiler will automatically put the @synthesize statement in for you if you leave it out. This is a good thing (less typing, less redundancy, less things to get wrong), but it could be confusing if you’re not expecting it. For example, my point 1 above will not apply with new versions.