How to distinguish between AnyObject (or Int) type in Xcode 9 - new Swift compiler

I need to check the type of AnyObject that has been assigned the value Int (or Int16 or UInt8), i.e.

In Xcode 8 - switching object using cases: is Uint8, is Int16, is Intrunning pefrect.
In Xcode 9 - it always introduces the first case, possibly true.

Here is an example code for a playground:

var t1: AnyObject?
var t2: AnyObject?

t1 = 30 as AnyObject
t2 = Int16(30) as AnyObject

if let obj1 = t1 {
    switch obj1 {
    case is UInt8:
        print("UInt8")
    case is Int16:
        print("Int16")
    case is Int:
        print("Int")
    default:
        break
    }
}

if let obj2 = t2 {
    switch obj2 {
    case is UInt8:
        print("UInt8")
    case is Int16:
        print("Int16")
    case is Int:
        print("Int")
    default:
        break
    }
}

Xcode 8 game consoles: Int
Int16

Xcode 9 game consoles: uint8
Uint8

and. Can someone explain why and / or attached any documentation about this?
B. Would be glad someone could help me achieve the same functionality in Xcode 9.

Thank.

+4
1

Swift 3 Any, AnyObject

var t1: Any?
var t2: Any?

t1 = 30 as Any
t2 = Int16(30) as Any
...

.

, AnyObject NSNumber, .

+2

Source: https://habr.com/ru/post/1687619/


All Articles