カスタムクラスを作成するときは、クラスのインスタンスを作成するときに、コードのallocinit部分をスキップできるようにしたいと思います。それがどのように行われるかに似ています:
NSString * ex = [NSString stringWithFormat...];
基本的に、基本変数を設定するためのカスタム初期化メソッドを使用してクラスを設定しています。しかし、私がフロントエンドにいて、実際にこれらの生き物を作っているとき、私は言わなければなりません:
[[Monster alloc] initWithAttack:50 andDefense:45];
そして私はむしろ言うことができたい
[Monster monsterWithAttack:50 andDefense:45];
alloc部分を削除するのは単純な愚かなことですが、コードが読みやすくなるので、そのようにしたいと思います。私はもともと自分の方法をから変更しようとしました
-(id)initWithAttack:(int) a andDefense:(int) d
に
-(id)monsterWithAttack:(int) a andDefense:(int) d
そして、に変更self = [super init]
しますself = [[super alloc] init];
が、それは明らかに機能しません!何か案は?