メモリ管理、カスタムサブクラスで独自のサブクラスのカスタムinitメソッドを書く正しい方法、および配列。objective-cのinitメソッドでself.propertyを使用する方法、initメソッドで配列を初期化する方法
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSMutableArray *array;
@property (nonatomic, retain) SomeSubclassOfNSObject *object;
@interface SomeSubclassofNSObject
@property (nonatomic, retain) NSString *category;
私のinitメソッドの記述方法は?
は、あなたが実行します。
initWithName:(NSString *)aName object:(SomeSubclassOfNSObject *)anObject {
if (self = [super init]) {
self.name = aName; // or do you do name = aName or name = [aName copy] autorelease] or name = [NSString alloc] initWithFormat:@"%@", aName]
self.object = anObject; // do I need to make a copy of this object so they don't point to the same object?
// loop through NSMutableArray and copy the objects?
// not really sure what to do for arrays.
}
return self;
}