仍然是Objective C的新手,並且我遇到了一些麻煩,我似乎無法自己弄清楚。對於以下前三個@properties中的每一個,錯誤都會發生兩次,並且是: 錯誤:「之前的語法錯誤」)「令牌」。Obj C - 隨機@property錯誤
#import <Foundation/Foundation.h>
@interface PolygonShape : NSObject {
int *numberOfSides;
int *minimumNumberOfSides;
int *maximumNumberOfSides;
}
@property (setter = setNumberOfSides) int *numberOfSides;
@property (setter = setMin) int *minimumNumberOfSides;
@property (setter = setMax) int *maximumNumberOfSides;
@property (readonly, getter = angleInDegrees) float *angleInDegrees;
@property (readonly, getter = angleInRadians) float *angleInRadians;
@property (readonly, getter = name) NSString *name;
- (id) init;
- (id) initWithSides: (int*) sides min: (int*) min max: (int*) max;
- (void) dealloc;
- (BOOL) setNumberOfSides: (int*) num;
- (void) setMin: (int*) num;
- (void) setMax: (int*) num;
- (void) description;
- (float*) angleInDegrees;
- (float*) angleInRadians;
- (NSString*) name;
@end
不知道這是否會有所作爲,但這裏是執行的彙總版本:
#import "PolygonShape.h";
@implementation PolygonShape
@synthesize numberOfSides;
@synthesize minimumNumberOfSides;
@synthesize maximumNumberOfSides;
...
- (BOOL) setNumberOfSides: (int*) num {
if(num > minimumNumberOfSides && num < maximumNumberOfSides) {
[numberOfSides release];
numberOfSides = [num retain];
return YES;
} else {
NSLog(@"Number %i is out of range %i to %i", num, minimumNumberOfSides, maximumNumberOfSides);
return NO;
}
}
- (BOOL) setMin: (int*) num {
if(num > 2 && num <= maximumNumberOfSides) {
[minimumNumberOfSides release];
minimumNumberOfSides = [num retain];
return YES;
} elseif (num > 2 && maximumNumberOfSides == nil) {
[minimumNumberOfSides release];
[self setMax: 12];
minimumNumberOfSides = [num retain];
return YES;
} elseif (num > 2) {
NSLog(@"Polygons must have more than 2 sides.");
return NO;
} else {
NSLog(@"Please enter a number less than or equal to %i, the current maximum", maximumNumberOfSides);
return NO;
}
}
- (void) setMax: (int*) num {
if(num <= 12 && num < maximumNumberOfSides) {
[maximumNumberOfSides release];
maximumNumberOfSides = [num retain];
} elseif (num <= 12) {
NSLog(@"Please enter a number less than or equal to 12");
} else {
NSLog(@"Please enter a number greater than or equal to %i, the current minimum", minimumNumberOfSides);
}
}
...
@end
預先感謝您的幫助!
太棒了!一旦我把所有的指針都弄清楚了,這是唯一需要解決的問題,而且你看起來很明顯。非常感謝。 – bloudermilk 2008-12-29 06:27:50