for case let ... where

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

  • let: variable binding.

  • where: condition on bound variable.

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

โญ๏ธ ๆณจๆ„๏ผš for case let ... where ๅŠ ๆขไปถ็š„ๆ–นๅผ่ทŸ if/guard case let ไธไธ€ๆจฃโ—๏ธ

// mirror of `subject`
let mirror = Mirror(reflecting: subject)

// โญ for case let ... where 
//   (pattern-match tuples + data binding + condition)
// ------------------------------------------------------
//            โ†ฑ โญ child.label ignored     โ•ญโ”€โ”€ โญ where โ”€โ”€โ”€โ•ฎ
for case let (_, value) in mirror.children where value is T {
    // ...
}

// โญ for case let ... where
for case let .loaded(data) in states where data.count > 2
{ ... }

Last updated