Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 998
72A12F4E Avatar asked Feb 05 '26 00:02

72A12F4E


1 Answers

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.

__LINE__ The line number on which it appears.

__COLUMN__ The column number in which it begins.

__FUNCTION__ The name of the declaration in which it appears.

So i guess you cannot get the method parameters.

like image 76
ipraba Avatar answered Feb 06 '26 15:02

ipraba