このコードスニペットをネットで見つけました。これは、私がこれまでに見たことのない方法でNSMutableArrayをセットアップします(私はObj-Cの初心者です)。誰かがそれが何をしているのか、そしてなぜあなたがこのようにするのかを説明できますか?特に、@ syncronized、静的、およびメソッドシグネチャの小さなプラス記号。
add the following to the .h file:
+(NSMutableArray *)allMySprites;
add the following to he .m file after implementation:
static NSMutableArray * allMySprites = nil;
+(NSMutableArray *)allMySprites {
@synchronized(allMySprites) {
if (allMySprites == nil)
allMySprites = [[NSMutableArray alloc] init];
return allMySprites;
}
return nil;
}