switch case let ... as

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

๐Ÿ‘‰ ๆฏ”่ผƒ๏ผš if let ... as?

// switch on "protocol type"
switch medium {
  case let b as Book : // ... โญ๏ธ ๆณจๆ„๏ผš้€™่ฃก็”จ็š„ๆ˜ฏ `as` ไธๆ˜ฏ `as?`
  case let m as Movie: // ...
  default: // ...
}

Last updated