Under the hood, the operator switchuses the pattern matching operator ( ~=) to determine the comparisons that it can perform. In your case, it uses this version :
@warn_unused_result
public func ~=<T : Equatable>(a: T, b: T) -> Bool
Equatable . switch a, b. Bool , , a == b.
UITextField NSObject, Equatable isEqual. UITextFields , , switch.
isEqual . switch , UITextField , .
, :
if textField == stateField {
print("editing state")
} else if textField == countryField {
print("editing country")
} else {
// 'default' case
}
( NSObject ):
if textField.isEqual(stateField) {
print("editing state")
} else if textField.isEqual(countryField) {
print("editing country")
} else {
// 'default' case
}
switch - - , if else if.