I just can't get it! I have custom class "Word" also I generate NSMutableArray of Word-class-objects in few steps:
- words = [NSMutableArray array];
- for i = 0 to 8
- word = alloc+init;
- [words addObject: word];
- [word release];
Then I pass words instance to setter of another class:
someInstance.words = words;
Where words is nonatomic, retain property. I declare setWords method like this:
-(void)setWords:(NSMutableArray *)w {
[w retain];
[words release];
words = w;
}
When words come to method as "w" variable it is an array of object but when I retain it and assign to my old value my words variable becomes an NSMUtableArray and it count is equal to w.count, but items of array 0x0. The "=" operator does not copy items of array, how can I fix it? Please help, I am a newbie in objective-c. I instanciate Word only with one method, shoud I implement parameterless init method?
-(id)initWithId:(int)Id Word:(NSString *)Word Card:(int)Card {
self.id = Id;
self.word = Word;
self.card = Card;
return self;
}
The cycle where I generate my NSMutableArray:
Card *card = [[Card alloc] initWithId:[s intForColumn:@"id"] Type:[s intForColumn:@"type"] Used:[s intForColumn:@"used"]];
s = [db executeQueryWithFormat:@"SELECT w.id as id, word, card FROM word as w INNER JOIN card as c ON w.card=c.id WHERE c.id=%i ORDER BY w.id, RANDOM()", card.id];
while ([s next]) {
Word *word = [[Word alloc] initWithId:[s intForColumn:@"id"] Word:[s stringForColumn:@"word"] Card:[s intForColumn:@"card"]];
[card.words addObject:word];
[word release];
}
words = [w mutableCopy]in your setter method.