Позднее связывание

protocol IPC {
    func restart()
}

class MacBookIPC {
    var name = "MacBook"
    func restart() {}
}

let device: IPC = MacBook()

//type(of:) gives the DYNAMIC type of a value
let typeName = type(of: device)
//typeName is MacBook
print("typeName is \(typeName)")

//Mirror tells the same and adds the display style
let mirror = Mirror(reflecting: device)
//subjectType is MacBook
print("subjectType is \(mirror.subjectType)")
//displayStyle is class
print("displayStyle is \(mirror.displayStyle!)")

//"is" checks the type without unwrapping it
let isMacBook = device is MacBook
//isMacBook is true
print("isMacBook is \(isMacBook)")

//Types can be compared to each other
let same = type(of: device) == MacBook.self
//same is true
print("same is \(same)")