FROM : Jonathan Jackel
DATE : Sat Dec 11 18:34:12 2004
I suspect the problem is in your Word class. This should work:
NSMutableArray *myArray = [[NSMutableArray alloc] init];
NSString *word;
word = @"test0"
[myArray addObject:word];
word = @"test1"
[myArray addObject:word];
NSLog(@"Word 0: %@\nWord 1: %@", [myArray objectAtIndex:0], [myArray
objectAtIndex:1]);
I second Jonathon Mah's comments on your memory issues. It's possible
that you are not implementing setWord: or getWord properly because you
don't understand memory management yet. We might be able to help if we
saw that code.
Jonathan
On Dec 11, 2004, at 4:53 AM, Apirak wrote:
> Hello,
>
> I try to add two object to myArray by one variable. my source code is
> look like this
>
> NSMutableArray *myArray = [[NSMutableArray alloc] init];
>
> Word *word;
>
> word = [[Word alloc] init];
> [word setWord:@"test"];
> [myArray addObject:word];
>
> word = nil;
> word = [[Word alloc] init];
> [word setWord:@"test2"];
> [myArray addObject:word];
>
> Word *wd = [[myArray objectAtIndex:0] retain];
> NSLog(@"word equal %@", [wd getWord]);
>
> wd = [[myArray objectAtIndex:1] retain];
> NSLog(@"word equal %@", [wd getWord]);
>
> the result is
>
> word equal test2
> word equal test2
>
> but It should be
>
> word equal test
> word equal test2
>
> I am java developer, it very hard to deal with vector :(
>
> Apirak Panatkool
>
> e-mail: <email_removed>
> phone: 01-4033320
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (<email_removed>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>
>
DATE : Sat Dec 11 18:34:12 2004
I suspect the problem is in your Word class. This should work:
NSMutableArray *myArray = [[NSMutableArray alloc] init];
NSString *word;
word = @"test0"
[myArray addObject:word];
word = @"test1"
[myArray addObject:word];
NSLog(@"Word 0: %@\nWord 1: %@", [myArray objectAtIndex:0], [myArray
objectAtIndex:1]);
I second Jonathon Mah's comments on your memory issues. It's possible
that you are not implementing setWord: or getWord properly because you
don't understand memory management yet. We might be able to help if we
saw that code.
Jonathan
On Dec 11, 2004, at 4:53 AM, Apirak wrote:
> Hello,
>
> I try to add two object to myArray by one variable. my source code is
> look like this
>
> NSMutableArray *myArray = [[NSMutableArray alloc] init];
>
> Word *word;
>
> word = [[Word alloc] init];
> [word setWord:@"test"];
> [myArray addObject:word];
>
> word = nil;
> word = [[Word alloc] init];
> [word setWord:@"test2"];
> [myArray addObject:word];
>
> Word *wd = [[myArray objectAtIndex:0] retain];
> NSLog(@"word equal %@", [wd getWord]);
>
> wd = [[myArray objectAtIndex:1] retain];
> NSLog(@"word equal %@", [wd getWord]);
>
> the result is
>
> word equal test2
> word equal test2
>
> but It should be
>
> word equal test
> word equal test2
>
> I am java developer, it very hard to deal with vector :(
>
> Apirak Panatkool
>
> e-mail: <email_removed>
> phone: 01-4033320
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (<email_removed>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>
>
| Related mails | Author | Date |
|---|---|---|
| Apirak | Dec 11, 10:53 | |
| Jonathon Mah | Dec 11, 15:17 | |
| Jonathan Jackel | Dec 11, 18:34 | |
| Andrew Merenbach | Dec 12, 10:32 |






Cocoa mail archive

