In Swift 2, it was possible to test whether a value is an object by using is AnyObject
.
In Swift 3, however, all value types are automatically boxed in a _SwiftValue
object when typecast to AnyObject
. This means that the expression x is AnyObject
is always true in Swift 3. The compiler will even warn about this:
'is' test is always true
Swift 3’s autoboxing of values comes with a memory allocation cost. Is there a runtime test to determine whether a given value is an object in Swift 3?