Skip navigation.
 
mlRe: NSMutableArrya problems
FROM : Larry Fransson
DATE : Sat Dec 11 08:08:35 2004

On Dec 10, 2004, at 21:40, Apirak wrote:

> my -setWord and -getWord work very well, but it will show me an error
> after I get it from NSMutableArray.
>

>>> Word *wd = [[myArray objectAtIndex:0] retain];
>>> NSLog(@"word equal %@", [wa getWord]);

>
> I think it because  "retains or copies" problems that you said. // my
> basic skill is java don't know much about vector :p


In the code you posted, you never defined what "wa" is.  Perhaps you
meant to write

   NSLog(@"word equal %@", [wd getWord]);

It seems like that should work.

Another helpful tip:

> - (void) setWord:(NSString *)newword {
>     word = newword;
> }


That will leak memory every time you call it.  It should be written
more like this:

- (void)setWord:(NSString *)newWord
{
   [newWord retain];
   [word release];
   word = newWord;
}

You must release the old object before assigning a new one.

Larry Fransson
Seattle, WA

Related mailsAuthorDate
mlNSMutableArrya problems Apirak Dec 11, 05:14
mlRe: NSMutableArrya problems Apirak Dec 11, 06:40
mlRe: NSMutableArrya problems Larry Fransson Dec 11, 08:08
mlRe: NSMutableArrya problems mmalcolm crawford Dec 11, 11:15
mlRe: NSMutableArrya problems mmalcolm crawford Dec 11, 11:23