๐Ÿ”ฐTypecasting with Protocols

Swift โŸฉ Protocols โŸฉ Typecasting

// if let ... as? ...
if let p = person as? Programmer { 
    // ...
}

// switch ... case is ...
switch person { 
    case is Programmer:    // ...
    case is Player:    // ...
    default:    // ...
}

// for ... in where ... is ...
for person in people where person is Programmer { 
    // ...
}

Last updated