Switch structure in 11.swift
Difference One:
Switch condition in OC can only put integers
The switch condition in Swift can put almost any data type
Difference Two:
There should be a break in each case in OC, and if there is no break, it will continue down through the execution of the box until the break jumps out of the switch structure
There is no need to add a break statement at the end of the case branch in Swift, which jumps out of the switch structure when the case branch is completed
Difference Three:
In OC, not every case must have an executable statement, and if there is no executable statement and break in that branch, it will execute a multi-conditional match by executing the code in the branch that has the most recent executable statement below it.
There must be an executable statement behind each case in Swift,
PS: This difference is due to the existence of the difference between the two, Swift in the case of multi-condition matching is used in the syntax, cases followed by multiple conditions, separated by commas.
In addition, Swift's case can be filled in with a range as a match condition, such as a...b:
Difference Three:
Default in switch in OC is not required
Default in switch in Swift is required
The switch statement in Swift can use where to increase the judging condition
Such as:
var point = (10,-10)
Switch point{
Case let (x, y) where x = = y:
//
Case let (x, y) where x = =-Y:
//
Default:
//
}
The switch statement in Swift can use the Fallthrough keyword to perform a run-through, that is, after the current case is executed, the case that follows Fallthrough executes the default statement, similar to the case in OC without a break statement, With Fallthrough, however, a constant or variable cannot be defined in the following case condition, meaning that the case condition after Fallthrough cannot receive a point using a variable like let (x, y) in the code above, or there will be a syntax error.
The difference between OC and swift in interpreting statements