我正在學習The Big Nerd Ranch Guide第二版書中的Objective-C編程。我已經得到了能夠輕鬆第18章,但現在的Xcode更新我遇到的語法錯誤「使用未聲明的標識符‘heightInMeters’的。這是我的代碼是Objective-C的與NSObject的一個子類。使用未聲明的標識符
***AppDelegate.h***
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
{
// BNRPerson has two instance variables
float _heightInMeters;
int _weightInKilos;
}
// BNRPerson has methods to read and set its instance variables
- (float)heightInMeters;
- (void)setHeightInMeters:(float)h;
- (int)weightInKilos;
- (void)setWeightInKilos:(int)w;
// BNRPerson has a method that calculates the Body Mass Index
- (float)bodyMassIndex;
@end
***AppDelegate.m***
#import "AppDelegate.h"
@interface AppDelegate()
@property (weak) IBOutlet NSWindow *window;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
- (float)heightInMeters *USE OF UNDECLARED IDENTIFIER 'heightInMeters'
{
return _heightInMeters;
}
- (void)setHeightInMeters:(float)h
{
_heightInMeters=h;
}
- (int)weightInKilos
{
return _weightInKilos;
}
- (void)setWeightInKilos:(int)w
{
_weightInKilos=w;
}
- (float)bodyMassIndex
{
return _weightInKilos/(_heightInMeters * _heightInMeters);
}
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
@end
這是什麼應該是:' - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {(float)heightInMeters *使用UNDECLARED IDENTIFIER'heightInMeters'' – 2014-11-23 20:18:32