私はObjectiveCを初めて使用し、いくつかの非常に基本的なことに問題を抱えています。
で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