williamsandonz
williamsandonz

Reputation: 16420

Objective c property setters aren't working

Ive now identified a problem in a few diff classes in my iPhone Coco2d game, my first Objective-c go. My setters don't seem to be working! If I try access property after setting it's either NULL (if to Stringed) or I get a fatal bad access exception, I must be doing something wrong, heres my code:

@interface Character : CCNode 
    {
        CCSprite* sprite;
        int width;
        int height;
    }
    @property (retain) CCSprite* sprite;
    @property int width;
    @property int height;
@end

and implemntation:

@implementation Character

@synthesize sprite;
@synthesize width;
@synthesize height;

-(id) init
{
    if((self=[super init])) {
        [self setSprite :[CCSprite spriteWithFile:@"character.png"]];
        [self setWidth:28];
        [self setHeight:28];
        NSLog(@"About to try get height...");
        NSLog([self height]); //bad access exception
    }
}

Upvotes: 0

Views: 85

Answers (1)

James Webster
James Webster

Reputation: 32066

That's a poorly formatted log statement

NSLog(@"Height :%d", [self height]);

NSLog looks for a string to print, you've given it an int which can't be changed to an object

Upvotes: 4

Related Questions