Type (of :) in Swift 3 does not seem to work with type checking

type(of: x) in Swift 3 does not seem to work with type checking is

It just throws this error message:

Sequential line operators must be separated by ';'

Code example:

class Test : UIViewController {}

let test = Test()
let test2 = Test()
let isEqual = test2 is type(of: test) // this does not compile

What is wrong here?
How to perform dynamic type checking in Swift 3?

+4
source share
2 answers

In this specific context:

class Test : UIViewController {}

class Test1 : UIViewController {}

let test = Test()
let test2 = Test1()

let f = test2.isKind(of: test2.classForCoder)

print(f)

Output: true

It might be another idea for type checking

Besides

let q = type(of: test) == type(of: test)

Will return true, but only if it was the same class as the subclass

0
source

, , ==

test2 type(of: test).


:

print(type(of: test)) // Test
print(test2) // <__lldb_expr_22.Test: 0x7ffe8cb063e0>

let isEqual = type(of:test2) == type(of: test) // true
0

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


All Articles