How to get the arity of a method?
问题 In Javascript, for example, you can get the arity (the number of arguments a function is supposed to take) by simply func.length . How can I get this information for a method in Objective-C? 回答1: NSMethodSignature is awesome for all kind of reflection information. SEL selector = @selector(foo:); NSMethodSignature *sig = [someObj methodSignatureForSelector:selector] int argCount = [sig numberOfArguments]; 回答2: When there’s no receiver object to send -methodSignatureForSelector: to, it’s