From Xcode 4.4 onwards has Default Synthesis Of Properties. It generates this automatically:
@synthesize name = _name;
And from source2
readwrite vs readonly determines whether a synthesized property has a synthesized accessor or not (readwrite has a setter and is the default, readonly does not).
Therefore, I've concluded that @synthesize name = _name;
is not required for readwrite but it's needed for readonly
However, in Apple's spritekit Adventure code (adventure code download link), APAAdventureScene.m:
"heroes" (readwrite) is synthesize in the example. If it's not synthesize it will give this error: Use of undeclared identifier '_heroes'
Is @synthesize
required for readwrite property, I'm confuse?
Thank you
@interface APAAdventureScene () <SKPhysicsContactDelegate>
...
@property (nonatomic, readwrite) NSMutableArray *heroes; // our fearless adventurers
@property (nonatomic) NSMutableArray *goblinCaves; // whence cometh goblins
...
@end
@implementation APAAdventureScene
@synthesize heroes = _heroes;
- (id)initWithSize:(CGSize)size {
...
_heroes = [[NSMutableArray alloc] init];
_goblinCaves = [[NSMutableArray alloc] init];
...
}
- (void)updateWithTimeSinceLastUpdate:(CFTimeInterval)timeSinceLast {
// Update all players' heroes.
for (APAHeroCharacter *hero in self.heroes) {
[hero updateWithTimeSinceLastUpdate:timeSinceLast];
}
// Update the caves (and in turn, their goblins).
for (APACave *cave in self.goblinCaves) {
[cave updateWithTimeSinceLastUpdate:timeSinceLast];
}
}
@end