Newbie: I can't see what is wrong?
Newbie: I can't see what is wrong?
- Subject: Newbie: I can't see what is wrong?
- From: Michael Curtis <email@hidden>
- Date: Sun, 4 Jul 2004 17:14:24 +0100
Hi,
I have been trying to fix this for weeks and I can't see why it
doesn't work. I am sure it is something so, so simple, but now I have
looked at it to much and I am going around in cycles. I was hoping
someone would be kind enough to help. I am getting the following error.
2004-07-04 16:30:02.381 card_shuffle[3122] Loop 0 and Last 3
2004-07-04 16:30:02.382 card_shuffle[3122] *** -[cards objCType]:
selector not recognized
2004-07-04 16:30:02.383 card_shuffle[3122] *** Uncaught exception:
<NSInvalidArgumentException> *** -[cards objCType]: selector not
recognized
card_shuffle has exited due to signal 5 (SIGTRAP).
I am trying to compare two NSNumbers. If I hard code intCode it all
works fine, so I am assuming that what I am getting out of my diamonds
object isn't an NSNumber even though I thought I had added an NSNumber
to my array using the randomCardNumber variable.
I have enclosed all the code. I am sorry if it is a really silly
error, but I am very new at this.
Best wishes and thanks for any input.
Michael Curtis
ps - If this mailing list is the wrong place for beginners to post
questions can someone please point me towards a more Newbie mailing
list.
------
//
// cards.h
// card_shuffle
//
// Created by baz on Thu Jun 17 2004.
// Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "cards.h"
@interface cards : NSObject {
int cardsLeft;
int randomCard;
NSNumber *randomCardNumber;
}
- (int) cardsLeft;
- (void) setcardsLeft: (int) c;
- (void) randomCardNumber;
@end
------
//
// cards.m
// card_shuffle
//
// Created by baz on Thu Jun 17 2004.
// Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//
#import "cards.h"
@implementation cards
-(void) setcardsLeft: (int) c
{
cardsLeft=c;
}
-(int) cardsLeft
{
return cardsLeft;
}
-(void) randomCardNumber
{
randomCard = random () % 13 +1;
randomCardNumber = [NSNumber numberWithInt:randomCard];
}
-(NSString *) description
{
return [NSString stringWithFormat:@"%d",randomCard];
}
@end
------
#import <Foundation/Foundation.h>
#import "cards.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int i;
NSNumber *intCard, *intLoop;
NSMutableArray *diamonds;
cards *diamondsCards;
cards *entryToPrint;
srandom (time(NULL));
diamonds = [[NSMutableArray alloc] init];
intLoop = [NSNumber numberWithInt: 0];
for (i=0;i<13;i++)
{
diamondsCards =[[cards alloc] init];
[diamondsCards randomCardNumber];
[diamonds addObject:diamondsCards];
intCard = [diamonds objectAtIndex:i];
//With the line below it will work.
//intCard = [NSNumber numberWithInt:10];
intLoop = [NSNumber numberWithInt:i];
NSLog(@"Loop %@ and Last %@",intLoop, intCard);
//error occurs in this if statement
if ([intLoop isEqualToNumber: intCard] == YES)
{
NSLog(@"Match.");
}
}
for (i=0;i<13;i++)
{
entryToPrint = [diamonds objectAtIndex:i];
NSLog(@"Card Number %d = %@", i, entryToPrint);
}
[pool release];
return 0;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.