Is it possible to declare a protocol and also define the type of object that can conform to it?
I have a set of closures that I'd like to configure in various different subclasses of
In Objective C you were able to declare a variable like this:
UIViewController <Protocol> *variable;
Unfortunately, this is not possible with Swift, which considering how protocol-oriented Swift is, it's very strange.
This is pretty uncomfortable because like you found out, the compiler can't be aware of both the class and the protocol at the same time, so you have to cast twice, you have to check that the object is of the allowed class at runtime, and have to document it in your code to prevent people from sending the wrong kind of object.