はsmthです。この合法のように?コンパイルして実行しているようですが、大丈夫ですか?メソッド呼び出し内の静的な設定(シングルトンパターン付き)
私はこの方法では、nilに静的に自分を設定IAM意味を(私のメソッド内で、nilに自分自身を設定することを目指す)
static MyClass * StaticInstance = nil;
+ (MyClass *) sharedStaticInstance
{
if (StaticInstance == nil) {
StaticInstance = [[MyClass alloc] init];
}
return StaticInstance;
}
- (void) killStaticSelf
{
StaticInstance = nil;
}
以降
[[MyClass sharedStaticInstance] doSmth]; // our static instance is created
[[MyClass sharedStaticInstance] killStaticSelf]; // now its killed inside itself method
[[MyClass sharedStaticInstance] doSmth]; // now it should recreate again
非常によく目撃された –