mardi 11 septembre 2018

how to view all the methods in a class in swift at runtime without using objective-c libraries

I want to get the list of methods present in a class and their arguments list at runtime. I dont want to use any Objective-C runtime methods such as class_copyMethodList, can this be done using Mirror(reflecting: any) or any similar methods. I tried using wickwirew/Runtime but was not able to find a way to get the methods present in a class.

the class I want to Introspect is a simple class called maths

  import Foundation

 class Maths
{
    func add(a:Int,b:Int)->Int{
        return a + b
    }

    func sub(a:Int,b:Int)->Int{
        return a - b
    }

    func append(a:String,b:String)->String{
        return a + b
    }
}

at runtime I just want to get the list of methods like add ,sub, append and the type of arguments that they accept.

thank you.





Aucun commentaire:

Enregistrer un commentaire