2014-11-23 2 views
-1

The Big Nerd Ranch Guide 제 2 판에서 객관적 - C 프로그래밍을 배우고 있습니다. 내가 쉽게 장 (18)에 입수했습니다하지만 지금은 그 엑스 코드 내가 선언되지 않은 식별자 'heightInMeters'의 구문 오류 "사용을 경험하고 업데이트되었습니다. 여기에 NSObject의 서브 클래스와 목표 - C 내 코드입니다.선언되지 않은 식별자 사용

***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 
+0

:'' - (void) applicationDidFinishLaunching : (NSNotification *) a 알림 { - (float) heightInMeters * 비 식별 IDENTIFIER의 사용 'heightInMeters'' –

답변

1

나는 이유를 알고하지 않습니다 시도해보십시오.이 있어야하는데 무엇

// 
// AppDelegate.m 
// Test 
// 
// Created by JK on 11/23/14. 
// 
// 

#import "AppDelegate.h" 

@interface AppDelegate() 

@property (weak) IBOutlet NSWindow *window; 
@end 

@implementation AppDelegate 

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { 

} 

- (float)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 
+0

이 코드는 컴파일러에서 작동하는 내 질문에 대답 해 주셔서 감사합니다. 당신의 도움은 내 구문을 살펴볼 때 많은 시간을 아끼지 않았습니다. 시간 내 주셔서 감사합니다. – Kevin

+0

내 답변을 수락하여 감사를 표시하면 나, 당신, 그리고 SO 커뮤니티에 도움이 될 것입니다 :) – Jackson

0

당신은 아래 applicationDidFinishLaunching에서 당신의 메소드 구현을해야합니다.

당신이 방법 안에 방법을두고있는 것 같습니다
@implementation AppDelegate 

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { 

} 

- (float)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 
}