これはARCとは関係ないと思います。違いは、ARC を使用すると、コンパイラが警告/エラーを表示することです。
一般に、クラス メソッド (- ではなく + で始まり、別の方法で呼び出されるもの) では、self は特定のオブジェクトを参照しません。クラスを指します。[self alloc] を使用すると、サブクラス化されているかどうかに関係なく、まさにそのクラスのオブジェクトを作成できます。これがインスタンス メソッド [[self class] alloc] であれば、まったく同じように機能します。しかし、あなたは正当な理由でクラスメソッドにいます。
この場合、結果を返さないのはなぜですか?
+ (id)itemWithTitle:(NSString *)title target:(id)target action:(SEL)action
{
return [[self alloc] initWithTitle:title target:target action:action];
}
クラス名が Foo の場合は、次のようになります。
+ (id)itemWithTitle:(NSString *)title target:(id)target action:(SEL)action
{
Foo *newMe = [[self alloc] initWithTitle:title target:target action:action];
// Here you have access to all properties and methods of Foo unless newMe is nil.
return newMe;
}
または、Foo のメソッドとプロパティにアクセスすることなく、より一般的に:
+ (id)itemWithTitle:(NSString *)title target:(id)target action:(SEL)action
{
id newMe = [[self alloc] initWithTitle:title target:target action:action];
return newMe;
}