The switch statement value binding pattern in Swift development

  • 2020-05-15 02:14:38
  • OfStack

Switch profile

Switch has also been added to Swift as an essential statement in the selection structure. Anyone with programming experience will be familiar with Switch statements, but apple has greatly enhanced Switch to include features not found in other languages.


 //    switch Statement value binding mode 
    let point = (100, 10)
    switch point {
      //  If there is a match, it will not be executed 1 A the   That's ok case let (x, y)
    case (let x, let y):
      print("\(x): \(y)")
      //  You can also add a judgment, and at the same time satisfy the match   At the same time  x == -10
    case (let x, 10)  where x == -10:
      //  matching y Coordinate for 10  the 
      print(x);
    default:
      print(" other ")
    }

Related articles: