Xcode 8 beta 6 has replaced AnyObject
by Any
.
In some cases I used a.classForCoder
for debugging reasons to see what's in it. With AnyObject
this worked. With Any
this doesn't work any more.
Now that I have to use Any
: what is the preferred way to see what type is in a variable of type Any
?
Casting to AnyObject
appears not to be very useful since in many cases this is a String
and String
doesn't confirm to AnyObject
any more since Xcode 8 beta 6.
Using type(of:)
You can use
type(of:)
to find out what type of variable is in a variable of typeAny
.Using classForCoder
classForCoder
is still there, and you can cast a value of typeAny
toAnyObject
, but if the value is a Swift value type, you'll get a converted result and not the original type: