... as! ...

Swift โŸฉ Pattern Matching โŸฉ Sentence Patterns โŸฉ

  • as!: force type casting.

๐Ÿ’พ ็จ‹ๅผ๏ผš Mirror.handleChildren()

// mirror self
let mirror = Mirror(reflecting: self)

//            โ†ฑ child.label ignored        โ•ญโ”€โ”€โ”€ โญ where clause โ”€โ”€โ”€โ”€โ•ฎ
for case let (_, value) in mirror.children where value is Resettable {

    // โญ `as!` force type casting (from Any to Resettable)
    //    "where clause" ensures `value` IS `Resettable`!
    (value as! Resettable).reset()
}

Last updated