我對Objective C非常陌生,並且遇到了一些非常基本的問題。
在AppDelegate.m
,我發現了以下錯誤:在目標C中使用未聲明的標識符
使用未聲明的標識符 '
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
有了這個,我得到了「隱式轉換'int'到'id'不允許使用ARC」 – WorkForPizza 2012-08-04 21:20:58
@WorkForPizza啊我明白了。但那不是我的錯,你的原始代碼是錯誤的。 – 2012-08-04 21:23:29
@WorkForPizza那是因爲你傳遞了一個標量類型(在你的情況下是整數值'100'和'10')而不是一個對象 – JustSid 2012-08-04 21:23:36