In Javascript, for example, you can get arity (the number of arguments the function should take) just func.length . How can I get this information for a method in Objective-C?
func.length
NSMethodSignature is terrific for all kinds of reflection information.
NSMethodSignature
SEL selector = @selector(foo:); NSMethodSignature *sig = [someObj methodSignatureForSelector:selector] int argCount = [sig numberOfArguments];
If the receiving object does not send -methodSignatureForSelector: to, you can use it NSStringFromSelector() and count the number of occurrences of the colon character.
-methodSignatureForSelector:
NSStringFromSelector()
From Objective-C Link to the working environment
method_getNumberOfArgumentsReturns the number of arguments accepted by the Method.unsigned method_getNumberOfArguments (method method) Parameter method Pointer to the data structure of the method. Go through the method in question. The return value is an integer containing the number of arguments accepted by this method.
method_getNumberOfArguments
Returns the number of arguments accepted by the Method.
unsigned method_getNumberOfArguments (method method) Parameter method Pointer to the data structure of the method. Go through the method in question. The return value is an integer containing the number of arguments accepted by this method.
Source: https://habr.com/ru/post/1336677/More articles:GetContentHeight () not working properly - androidProblems loading Classloader in Tomcat 6 - javajQuery Compute window yScroll position - jqueryHow to determine if @selector wants a parameter? - objective-c#if, #else, #endif in C # source code - c #Return null or throw exception again - javadatabase design for notification settings - databaseHow to use startproject (django-admin.py) if django project already exists? - pythonRails routes an invalid URL - ruby-on-railsHow to select xpath script in html head? - xpathAll Articles