samedi 14 novembre 2015

Swift2 reflection help. Convert the value I get (type Any?) to Bool or Bool? accordingly

for a unit test of mine, I wrote a small helper that can get me a property Value by name.

let m = Mirror(reflecting: self)
let child1 = m.descendant(name)

now the problem is that the child has Type Any? but the properties real type is e.g. Bool? So Any is actually an Optional!

Thats why if child1 is Bool? never fires because Any? isn't the Bool?.
But child1! is Bool? doesn't compile.
And child1! is Bool isn't true!

So how do I 'unbox' this reflected Any? value?





Aucun commentaire:

Enregistrer un commentaire