【发布时间】:2013-03-28 04:32:44
【问题描述】:
鉴于……
@interface Hog : NSObject { NSUInteger one, two, three; }
@property (strong, nonatomic) NSString *four, *five, *six;
-(void) seven;
@end
@implementation Hog
static CGFloat f, ff, fff;
- (NSString*) six { return _four = _five = _six = @"sexy"; }
- (void) seven { one = two = three = 33;
f = ff = fff = 6.66;
SEL sevenSelect = @selector(seven);
NSLog(@" %ld, %0.2f, %@, %@",
three, fff, self.six, NSStringFromSelector(sevenSelect)); }
@end
int main(int argc,char *argv[]){ Hog *u = Hog.new; [u seven];}
Output: 33, 6.66, sexy, seven
那么..那为什么不能声明
-(void)seven, eight, nine;
在标题等?有什么不同? objc-c 不只是对待IMP、或任何它,与任何其他变量、块等一样吗?无论如何,为什么还要打扰原型呢?特别是,如果它在类扩展中,为什么还要麻烦,而您只是要直接在下面编写方法。这似乎只是另一个犯错的机会,不必要的重复,不是吗?我知道我错了,但我要求接受教育,所以继续吧。
【问题讨论】:
-
因为不是。这是一种语言(C)。它以它的工作方式工作。 — 当然,在现代 Objective-C 中,您无论如何都不需要声明方法(除非您将它们公开在 .h 文件中)。
-
这对于像
- (id)initWithObjects:(id)firstObj, ...这样的原型来说是非常模糊的。
标签: objective-c c methods syntax prototype