Is there a limit to the amount of arguments I can pass to a method?

I am just wondering if there is a limit to the amount of arguments I can pass to a method in Objective-C using the following style:

- (void)example:(int)i forTime:(int)i forDate:(NSDate *)date etc etc

This is of course hypothetical, but I just find it interesting to know the reason behind such limitations (for example the character limit in URL's and such), and I love to see other people's opinions on questions like these on StackOverflow

And even with a limit on the number of arguments allowed to be passed, would it still be possible to pass NSArray 's containing objects as arguments and then just call on these objects from the array in the method using objectAtIndex ?


I quickly wrote a short program in C to generate a test method and call based on the desired inputted number of arguments, as per Hot Licks suggestion. Just made a method that takes 1,000 NSNumber arguments and it worked fine. Took up two pages in Xcode on my monitor, but it ran with no warnings or anything. Might try 10,000 later, but it seems there are no limits other than any imposed by hardware capabilities, etc.


No there is no limit to the number of arguments

The only limiting factor is the stack size of the process on a given architecture since method parameters are put on the stack.

链接地址: http://www.djcxy.com/p/11170.html

上一篇: 我应该使用NSOperationQueue和NSOperation而不是NSThread吗?

下一篇: 我可以传递给一个方法的参数的数量是否有限制?