到目前为止,我认为-(void)startToDoSomethingWithThis:(That*)thing andThat:(That*)otherThing
具有以下“方法签名”,同时也是选择器:-startToDoSomethingWithThis:andThat:
但现在有人说选择器不像方法签名,方法签名也包含参数及其类型。这是对的吗?
答案 0 :(得分:8)
选择器是类中方法的名称。它用于识别方法,最常见的是在调用方法时。签名是参数和返回类型的描述。它在调用任意方法时使用,例如通过NSInvocation来安排参数并为返回值腾出空间。许多选择器可能具有相同的签名。
SEL aSelector = @selector(method:foo:);
NSMethodSignature *aSignature = [theObject methodSignatureForSelector:aSelector];
NSMethodSignature是objc_method_description类型的包装。
答案 1 :(得分:5)
这是对的。选择器是方法名称。方法签名是返回类型和参数类型的封装。您可以使用+[NSObject instanceMethodForSelector:]
内省方法签名,NSMethodSignature
返回{{3}}个对象。