好這裏是該死的東西:Objective-C的Condtions運營商的怪事
- (void)setMinimumNumberOfSides:(NSNumber *)newMinimumNumberOfSides {
if (newMinimumNumberOfSides != minimumNumberOfSides) {
NSNumber *minimum = [[NSNumber alloc] initWithInt:(int)2];
if (newMinimumNumberOfSides > minimum) {
[newMinimumNumberOfSides retain];
[minimumNumberOfSides release];
minimumNumberOfSides = newMinimumNumberOfSides;
} else {
NSLog(@"setMinimumNumberOfSides: Invalid number of sides: %@ is smaller than the minimum of %@ allowed.",
newMinimumNumberOfSides, minimum);
}
[minimum release];
[newMinimumNumberOfSides release];
}
}
有一些奇怪的在那裏怎麼回事!問題是我的if(newMinimumNumberOfSides> minimum){}條件。即使newMinimumNumberOfSides比最小值大,它也會進入else語句。
我所做的:
NSNumber *minimum = [[NSNumber alloc] initWithInt:(int)6];
[polygon setMinimumNumberOfSides:minimum];
比2的方式更多,我收到我的錯誤信息......
我嘗試NSLog的這兩個,和它給了我正確的數字..那麼這是怎麼回事?
非常感謝!
這是非常邏輯,非常感謝! – TomShreds 2010-01-16 20:26:15