As rmaddy says, only a UIView
can be superview of a view- not a UIViewController
. A view controller has a view
, but it itself is not a UIView
. This is why the compiler tells you that they are unrelated types.
You're on the right track as far as checking types goes. In Swift, you've already found that dynamic type checking is done using the is
keyword. However, since you also want to use your subclass's implementation of segueAnimation()
, the preferred method would be to use the as
keyword for type casting.
if let VC = VC as? oneVC {
print("one")
VC.segueAnimation() // Use oneVC's segueAnimation method
} else if let VC = VC as? anotherVC {
print("another")
VC.segueAnimation() // Use anotherVC's segueAnimation method
} else {
fatalError("We only have two VC's")
}
Of course, you should still reconsider where you are putting this check. Any segue preparation and execution should be done by a view controller, not the view itself.