I am new to programming and is in the process of learning objective-c from Big Nerd Ranch. Using x-code, I am trying to create a class. Upon creating the class, X-Code is not recognizing it in main file. I created a new project, then created a new file ensuring the correct target was selected. When I try to type triangle, it says "Use of undeclared identifier." What am I doing wrong? Please help.
This is my header file.
#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
And this is my implementation file.
#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
[self lengthSideA]from inside the class, you can use directlylengthSideAor_lengthSideAfor auto-generated ivars.