Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective-c NSMutableArray of Objects retain
    primarykey
    data
    text
    <p>I just can't get it! I have custom class "Word" also I generate NSMutableArray of Word-class-objects in few steps:</p> <ol> <li>words = [NSMutableArray array];</li> <li>for i = 0 to 8</li> <li>word = alloc+init;</li> <li>[words addObject: word];</li> <li>[word release];</li> </ol> <p>Then I pass words instance to setter of another class:</p> <pre><code>someInstance.words = words; </code></pre> <p>Where words is nonatomic, retain property. I declare setWords method like this:</p> <pre><code>-(void)setWords:(NSMutableArray *)w { [w retain]; [words release]; words = w; } </code></pre> <p>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?</p> <pre><code>-(id)initWithId:(int)Id Word:(NSString *)Word Card:(int)Card { self.id = Id; self.word = Word; self.card = Card; return self; } </code></pre> <p>The cycle where I generate my NSMutableArray:</p> <pre><code>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]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload