通过获取指标的Objective-C方法的参数 [英] Get arguments of objective-c method by index

查看:170
本文介绍了通过获取指标的Objective-C方法的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,Objective-C的方法实际上是c函数,那前两个参数是自我和_cmd。我试图让剩余的参数作为数组(包括或排除,自我和_cmd)

I know that objective-c methods are actually c function, and that the first two arguments are self and _cmd. I'm trying to get the remaining arguments as an array (including or excluding, self and _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)
}

我试图做的是一样的东西:

What I'm trying to do is something like:

[self doOtherMethod:@selector(otherMethod:withObject:andObject:) withObjects:args];

所以,我怎么能得到传递给方法的参数数组(三阵,甚至NSArray的),这样​​我可以通过他们或通过他们列举?

So how can I get an array (c array or even NSArray) of the arguments passed to the method, so that I can pass them on or enumerate through them?

编辑:我要与现有的方法,例如,要做到这一点委托方法,我不能改变。

I want to do this with existing methods, e.g. delegate methods that I can't change.

推荐答案

有关参数传递的机制体系结构相关,并可能涉及在寄存器值传递,堆栈,或者两者上。试图揪出的参数列表动态比调试目的以外的任何可能不是一个好主意,当然也不便于携带。

The mechanism for argument-passing is architecture-dependent, and may involve passing values in registers, on the stack, or both. Trying to ferret out the list of arguments dynamically for anything other than debugging purposes is probably not a good idea, and certainly not portable.

下面是我觉得这是一个伟大的起点,获得更深入地了解如何参数传递的文章: http://en.wikipedia.org/wiki/Calling_convention

Here's an article that I think would be a great starting point for gaining more insight into how arguments are passed: http://en.wikipedia.org/wiki/Calling_convention

这篇关于通过获取指标的Objective-C方法的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆