for case let ... where

SwiftPattern MatchingSentence Patterns

  • let: variable binding.

  • where: condition on bound variable.

💾 程式: Mirror.handleChildren()

// 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

Was this helpful?