for case let ... where
Swift ⟩ Pattern Matching ⟩ Sentence Patterns ⟩
💾 程式: 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
{ ... }⭐️ 注意:下列程式碼雖然類似 for case let ... where,但完全沒有用到 pattern matching 的概念喔❗️
// for ... in ... where
for item in array where item.year > 2000 { … }Mirror.handleChildren() - use
if case let ... wheresentence pattern.
Last updated
Was this helpful?