【发布时间】:2010-06-22 16:19:07
【问题描述】:
到目前为止,我认为-(void)startToDoSomethingWithThis:(That*)thing andThat:(That*)otherThing具有以下“方法签名”,同时也是选择器:-startToDoSomethingWithThis:andThat:
但是现在有人说选择器不像方法签名,方法签名还包含参数及其类型。对吗?
【问题讨论】:
标签: objective-c
到目前为止,我认为-(void)startToDoSomethingWithThis:(That*)thing andThat:(That*)otherThing具有以下“方法签名”,同时也是选择器:-startToDoSomethingWithThis:andThat:
但是现在有人说选择器不像方法签名,方法签名还包含参数及其类型。对吗?
【问题讨论】:
标签: objective-c
选择器是类中方法的名称。它用于标识方法,最常见的是在调用它时。签名是对参数和返回类型的描述。它在调用任意方法时使用,例如通过 NSInvocation 来安排参数并为返回值腾出空间。许多选择器可能具有相同的签名。
SEL aSelector = @selector(method:foo:);
NSMethodSignature *aSignature = [theObject methodSignatureForSelector:aSelector];
NSMethodSignature 是 objc_method_description 类型的包装器。
【讨论】:
没错。选择器是方法名称。方法签名是返回类型和参数类型的封装。您可以使用+[NSObject instanceMethodForSelector:] 内省方法签名,它返回一个NSMethodSignature 对象。
【讨论】:
NSMethodSignature 不记录与其相关的选择器。