我对Objective C非常陌生,并且在一些非常基本的事情上遇到了麻烦。
在AppDelegate.m
,我收到以下错误:
使用未声明的标识符“
health
”
使用未声明的标识符“attack
”
代码(分别):
[Troll setValue:100 forKeyPath:health];
[Troll setValue:10 forKeyPath:attack];
我不太确定如何声明标识符。
AppDelegate.m
#import "AppDelegate.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSObject *Troll = [[NSNumber alloc]init];
[Troll setValue:100 forKeyPath:health];
[Troll setValue:10 forKeyPath:attack];
return YES;
}
@end
AppDelegate.h
#import `<UIKit/UIKit.h>`
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
@interface Troll : NSObject {
NSNumber *health;
NSNumber *attack;
}
@end