dimanche 22 janvier 2017

Get name of function from reference to it

Given the following, Is it possible to use some sort of reflective mechanism in Swift/Obj-C to get the string "foo" from the reference bar?

I've looked at this and some other SO posts, but they seem to be focused on apply reflection to classes, not lone functions. I saw method_getName, but I don't know how to translate a Swift function to a Method object.

func foo(p1:Any, p2:String) -> Int {
    return -1
}
func getName(fn:Any) -> String {
    return // name of fn
}
print(getName(fn))





Aucun commentaire:

Enregistrer un commentaire