The*_*vat 1 iphone xcode syntax-error compile-time
xcode 4.2中的代码
游戏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
Run Code Online (Sandbox Code Playgroud)
游戏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
Run Code Online (Sandbox Code Playgroud)
我完全(或几乎完全)和书中一样,但我得到了错误消息:
description
不是类方法,而是实例方法.你创建的是一个类方法:+(NSString*)description;
.您不应尝试在类方法中访问实例属性(ivars).更改+
成-
.祝好运!
归档时间: |
|
查看次数: |
2167 次 |
最近记录: |