[英]Get swift function parameters dynamically
I am experimenting with a debug logging tool, and I want each run of a function to print out the Class Name, instance, function name, and its parameters. 我正在试验一个调试日志工具,我希望每次运行一个函数来打印出类名,实例,函数名及其参数。 This is what I have so far
这就是我到目前为止所拥有的
class Object {
func exampleFunction(parameter1: String, parameter2: Int) {
print("\(self.dynamicType)."+__FUNCTION__+"( <TODO: INSERT ALL PARAMETERS HERE AUTOMAGICALLY> )")
//do function stuff
}
}
Is there a way I can get the parameter list dynamically the similarly to how I get the function name and class type? 有没有一种方法可以动态获取参数列表,就像我获取函数名称和类类型一样?
EDIT: I found this question on stack overflow that is trying to do a similar thing, but they don't know how to get the parameters. 编辑:我发现这个问题在堆栈溢出试图做类似的事情,但他们不知道如何获取参数。
The only official documentation on those literals is here 关于这些文字的唯一官方文件在这里
Which only describes about the following 其中仅描述了以下内容
__FILE__
The name of the file in which it appears. __FILE__
它出现的文件的名称。
__LINE__
The line number on which it appears. __LINE__
显示的行号。
__COLUMN__
The column number in which it begins. __COLUMN__
的列号。
__FUNCTION__
The name of the declaration in which it appears. __FUNCTION__
它出现的声明的名称。
So i guess you cannot get the method parameters. 所以我猜你不能得到方法参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.