Classes Vc1 and Vc2 are subclasses of UIViewController:
class Vc1: UIViewController { .... }
class Vc2: UIViewController { .... }
The following code compiles without errors:
func onVCComplete(senderType: UIViewController.Type, details: Any) {
if senderType == Vc1.self {
/* ... */
}
else
if senderType == Vc2.self {
/* ... */
}
else {
fatalError("Unrecognised sender type: \(senderType)")
}
However I find it more readable with switch
statement:
func onVCComplete(senderType: UIViewController.Type, details: Any) {
switch senderType {
case Vc1.self: /* ... */
case Vc2.self: /* ... */
default: fatalError("Unrecognised sender type: \(senderType)")
}
}
This time I get compilation error: Expression pattern of type 'Vc1.Type' cannot match values of type 'UIViewController.Type'
.
Tried Any.Type
instead of UIController.Type
- same error.
Is this supposed to be?