Xcode 4.4 以降には、プロパティのデフォルト合成があります。これは自動的に生成されます:
@synthesize name = _name;
そしてsource2から
readwrite と readonly は、合成されたプロパティに合成されたアクセサーがあるかどうかを決定します (readwrite には setter があり、デフォルトですが、readonly にはありません)。
@synthesize name = _name;
したがって、読み取り書き込みには必要ありませんが、読み取り専用には必要であると結論付けました
ただし、Apple のスプライトキット アドベンチャー コード (アドベンチャー コードのダウンロード リンク) では、 APAAdventureScene.m:
この例では、「heroes」(読み書き) が合成されています。合成されていない場合は、次のエラーが発生します: Use of undeclared identifier '_heroes'
@synthesize
readwrite プロパティには必須ですが、混乱していますか?
ありがとうございました
@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