我对 Objective-C 相当陌生,并创建了这个基本程序。它在该@interface
部分上给了我错误,是否有任何简单的解释可以让初学者了解如何构建@interface
和@implementation
部分?下面的程序有什么问题?
#import <Foundation/Foundation.h>
@interface Rectangle : NSObject {
//declare methods
- (void) setWidth: (int) a;
- (void) setHieght: (int) b;
- (double) perimeter;
- (double) area;
}
@end
@implementation Rectangle
{
double area;
double perimeter;
int width;
int height;
}
- (void) setWidth: (int) a
{
width = a;
}
- (void) setHieght: (int) b
{
hieght = b;
}
@end
int main (int argc, const char * argv[])
{
NSAutoreleasePool * Rectangle = [[NSAutoreleasePool alloc] init];
int a = 4
int b = 5
int area = a * b;
int perimeter = 2 * (a +b);
NSLog(@"With width of %i and Hieght of %i", a, b);
NSLog(@"The perimeter is %i", perimeter);
NSLog(@"The Area is %i", area);
[pool drain];
return 0;
}