when [object copy] doesn't work ... :S

maccatalan

Registered
Hello.

I'm trying to make a new little game of Awale (an african strategy game).

My problem ? I'm trying to get an object from a NSMutableArray removing it from the array. When I execute a piece of code the application does nothing and the console of PB outputs : "2002-07-01 23:48:39.185 Cocowale[357] *** -[awale copyWithZone:]: selector not recognized". Here you've got the code, where awales is my array and currentAwale is an awale object (you've got the header after the bugged(?!) code) :

//-------------------------------------- this is where it fails
[currentAwale autorelease];
currentAwale = [[awales objectAtIndex:[awales count]-1] copy];
[awales removeObjectAtIndex:[awales count]-1];
//---------------------------------------

The awale class (the type of currentAwale) header :
//---------------------------------------
#import <Foundation/Foundation.h>

@interface awale : NSObject {
int trous[12];
int quiJoue;
int gains[2];
}

- (BOOL) play:(int)w;
- (int) trou:(int)w;
- (int) quiJoue;
- (int) gains:(int) qui;

@end
//---------------------------------------

I suppose the problem comes from the int type that is not similar to a NSObject children. So I should cerate some "copy" method. This is what I think. But here my two question : am I right ? and How to do ?

thank you very much
Pierre.
 
I am not entirely sure of this, but I think you have to implement the copy method. That is why you are getting selector not recognized.
 
Save yourself a lot of trouble and simply do this:

Code:
[currentAwale autorelease];
currentAwale = [[awales objectAtIndex:[awales count]-1] retain];
[awales removeObjectAtIndex:[awales count]-1];

No copy needed, but will work just fine and dandy. All you want to do is move the reference anyway, not make a duplicate.

HTH,
F-bacher
 
:D

thank you very much,
it seems to work ... well , it works !! :)

(now it is something else that doesn't work but well ... that's a first important step)

;)
 
Back
Top