I am learning objective-C programming from The Big Nerd Ranch Guide 2nd edition book. I have gotten to chapter 18 with ease but now that Xcode updated I am experiencing the syntax error "use of undeclared identifier 'heightInMeters'. Here is my code which is objective-c with a subclass of 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
It looks like you are putting methods inside a method. I don't know why. Try: