lundi 2 novembre 2015

Get a type of Element of an array in Swift (through reflection)

Let say I have following code

class Foo {
}

var fooArray : Array<Foo> = Array<Foo>()
// This is important because in my code I will get Any (vs Array<Foo)
var fooArrayAny : Any = foo

I want to be able to get a Type Foo out of variable fooArrayAny.

If I had fooArray, I would do something like that:

let type = fooArray.dynamicType.Element()

However, this doesn't work with fooArrayAny. It says that it has no member Element()





Aucun commentaire:

Enregistrer un commentaire