Reputation: 953
code in xcode 4.2
Game Model.h
#import <Foundation/Foundation.h>
@interface Game_Model : NSObject{
NSString *playerName;
int play;
int won;
}
@property (nonatomic,retain) NSString *playerName;
@property (nonatomic,readonly,assign) int play;
@property (nonatomic,readonly,assign) int won;
@end
Game Model.m
#import "Game Model.h"
@implementation Game_Model
@synthesize playerName,play,won;
+(NSString *)description{
return [NSString stringWithFormat:@"%@. Player:%@. Score: %d/%d",[super description],self.playerName,self.won,self.play];
}
@end
I made exactly (or nearly exactly) as in a book, but I got error messages:
Upvotes: 2
Views: 2201
Reputation: 1189
description
is not a class method, but an instance method. What you create is a class method: +(NSString*)description;
. You should not try to access instance properties (ivars) in a class method. Change +
into -
. Good luck!
Upvotes: 6
Reputation: 2557
I think that you are trying to refer to this
[super description]
and this might mess things around a little bit, try a return without that and see what happens
return [NSString stringWithFormat:@"Player:%@. Score: %d/%d",self.playerName,self.won,self.play];
Upvotes: 0