vendredi 26 juin 2015

Getting a function's return type in Swift

I realize that reflection isn't fully supported (yet) in Swift, but reflection run time methods are (apparently) supported. I'm trying to get the return type of a function at run time. Here's my example

let s:Selector = "willAnimateRotation"
var m:Method = class_getInstanceMethod(object_getClass(self),  s)
let returnType = method_copyReturnType(m)
println("method: \(m); returnType: \(returnType)")
free(returnType)

The output of this does not seem to vary depending on the return type of the selector. E.g., with String or Void return type for the selector, I get the following output:

method: 0x0000000000000000; returnType: 0x0000000000000000

Thoughts?

ALSO: I'm actually not really trying to do this in Swift. I'm bridging an Objective-C class to Swift, and am getting the same results there, when the Objective-C code attempts to determine the return type of a Swift selector. That is, my end-goal in this case happens to be to use Objective-C to get the return type of a Swift selector.





Aucun commentaire:

Enregistrer un commentaire