Re: pb with nsmutablearray
Re: pb with nsmutablearray
- Subject: Re: pb with nsmutablearray
- From: Charles Steinman <email@hidden>
- Date: Fri, 25 May 2007 08:31:46 -0700 (PDT)
NSTextTab declares -(float)location, so without the type information contained by the track variable (objectAtIndex: just returns an id), Cocoa is choosing that method signature. You have two choices: Either cast [trackList objectAtIndex:0] to the appropriate type or give the method an unambiguous name. I would recommend the second.
Cheers,
Chuck
julien ricard <email@hidden> wrote: hi,
I have an NSMutableArray of Track objects. After adding an instance of
Track to my array, displaying the location of the track works ok when
I get it directly from the Track object:
NSLog([track location]);
but it doesn't even compile when I get it from the array (error:
incompatible type for argument 1 of 'NSLog'):
NSLog([[trackList objectAtIndex:0] location]);
My main and Track.h are shown below. Anybody could help?
thanks
Julien
*******************main.m***********************
int main(int argc, char *argv[])
{
NSMutableArray *trackList = [[NSMutableArray alloc]
initWithCapacity:nTrack];
Track *track=[[Track alloc] init];
[track setLocation:@"track name"];
[trackList addObject:track];
NSLog([track location]);
NSLog([[trackList objectAtIndex:0] location]);
[trackList release];
return NSApplicationMain(argc, (const char **) argv);
}
*******************************************************
***********************Track.h****************************
@interface Track : NSObject
{
NSString *location;
}
@end
@implementation Track
-(id) init {
[super init];
location = [[NSString alloc] initWithString:@"None"];
return self;
}
-(void) setLocation:(NSString*) loc {
[loc retain];
[location release];
location = loc;
}
-(NSString*) location {
return location;
}
-(void) dealloc
{
[location release];
[super dealloc];
}
@end
************************************************
---------------------------------
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden