저는 프로그래밍에 익숙하지 않고 Big Nerd Ranch에서 objective-c를 배우는 중입니다. x- 코드를 사용하여 클래스를 만들려고합니다. 클래스를 만들면 X-Code가 주 파일에서이를 인식하지 못합니다. 새 프로젝트를 만든 다음 올바른 대상을 선택하도록 새 파일을 만들었습니다. 삼각형을 입력하려고하면 "선언되지 않은 식별자 사용"이라고 표시됩니다. 내가 도대체 뭘 잘못하고있는 겁니까? 도와주세요.Xcode에서 내가 만든 클래스를 인식하지 못하는 이유는 무엇입니까?
이것은 내 헤더 파일입니다.
#import <Foundation/Foundation.h>
@interface Triangle : NSObject
{
float lengthSideA;
float lengthSideB;
float lengthSideC;
}
@property float lengthSideA;
@property float lengthSideB;
@property float lengthSideC;
-(float) area;
-(float) perimeter;
-(float) hypothenuse;
@end
그리고 이것은 제 구현 파일입니다.
#import "Triangle.h"
@implementation Triangle
@synthesize lengthSideA, lengthSideC, lengthSideB;
-(float) perimeter
{
float a = [self lengthSideA];
float b = [self lengthSideB];
float c = [self lengthSideC];
return a + b + c;
}
-(float) area
{
float a = [self lengthSideA];
float b = [self lengthSideB];
return b * a/2;
}
-(float) hypothenuse
{
float a = [self lengthSideA];
float b = [self lengthSideB];
return sqrt(a * a + b * b);
}
@end
정확한 오류 메시지와 그것이 발생하는 코드 줄을 게시하십시오. – bbum
새로운 컴파일러를 사용하면 ivars를 선언 할 필요가 없습니다. 또한 클래스 내부에서 getter'[self lengthSideA]'속성을 호출 할 필요가 없으며 자동 생성 된 ivars에 대해 'lengthSideA' 또는'_lengthSideA'를 직접 사용할 수 있습니다. – redent84