【发布时间】:2011-11-05 17:59:17
【问题描述】:
我知道objective-c方法实际上是c函数,前两个参数是self和_cmd。我正在尝试将剩余的参数作为一个数组(包括或不包括 self 和 _cmd)
例如:
-(void)someMethod:(id)firstArg withObject:(id)secondArg andObject:(id)thirdArg {
//then something like:
args[0] //corresponds to self
args[1] //corresponds to _cmd
args[2] //corresponds to firstArg
args[3] //corresponds to secondArg
args[3] //corresponds to thirdArg
//or just start from firstArg being the 0th item in the index (skipping out self and _cmd)
}
我想做的是这样的:
[self doOtherMethod:@selector(otherMethod:withObject:andObject:) withObjects:args];
那么我怎样才能获得传递给方法的参数的数组(c 数组甚至 NSArray),以便我可以传递它们或枚举它们?
编辑:我想用现有的方法来做到这一点,例如我无法更改的委托方法。
【问题讨论】:
-
也许你可以用 ObjC 块做到这一点。
-
这实际上是一个非常困难的问题。
-
@DaveDeLong,如果你这么说,那对我来说是不可能的;)
-
@Jonathan。是的,可能获取当前方法调用的
NSInvocation,但需要很多工作。 -
@DaveDeLong,我现在只是很好奇,我想我在任何地方都找不到更多关于这个的信息?
标签: objective-c c