でNSAssertを使用する方法がわかりません。からが呼び出されると、静的変数は次のようになります(したがって、最初に呼び出され+alloc
たときに実行を停止する必要があります...)+alloc
+sharedGameManager
_sharedGameManager
nil
NSAssert
[self alloc] init]
+(GameManager*)sharedGameManager {
@synchronized([GameManager class])
{
if(!_sharedGameManager)
[[self alloc] init];
return _sharedGameManager;
}
return nil;
}
+(id)alloc
{
@synchronized ([GameManager class])
{
NSAssert(_sharedGameManager == nil,
@"Attempted to allocated a second instance of the Game Manager singleton");
_sharedGameManager = [super alloc];
return _sharedGameManager;
}
return nil;
}
ご回答有難うございます