Re: Newbie: I can't see what is wrong?
Re: Newbie: I can't see what is wrong?
- Subject: Re: Newbie: I can't see what is wrong?
- From: Stéphane Sudre <email@hidden>
- Date: Sun, 4 Jul 2004 19:37:01 +0200
On dimanche, juillet 4, 2004, at 06:14 PM, Michael Curtis wrote:
------
//
// 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;
Note: Bad idea to use an accessor name for this method.
@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];
Note: either you know what you're doing or you don't on this one.
randCardNumber will be released as soon as you reach the release of the
Autorelease Pool.
}
-(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;
intCard is said to be a NSNumber *.
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];
diamonds is an array of cards *.
intCard = [diamonds objectAtIndex:i];
you're getting a cards * and you're putting it in a NSNumber *.
//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.");
}
intCard is not a NSNumber *. It's a cards *
I think this is the problem but because I'm a bit jet lagged I'm not
100% sure.
_______________________________________________
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.