Here's a quick Swift TIL: starting with Swift 5.0 / Xcode 10.2, you can now constrain your protocols to certain subclasses. This example restricts protocol conformance to UIViews or UIView subclasses:

protocol MyViewProtocol: UIView {
}

// This can also be written as:

protocol MyViewProtocol where Self: UIView {
}

And this is just a reminder that Self (with a capital "S") in the context of a protocol means the type that is conforming to the protocol being declared.

Before Swift 5, the only way to do something like this was through a protocol extension (rather than directly in the protocol declaration itself):

protocol MyProtocol {
}

extension MyProtocol where Self: UIView {
}

It was also helpful to create a separate typealias with the combined type info for cleaning up call sites:

typealias MyViewProtocol = MyProtocol & UIView

But none of this is needed now thanks to this new Swift type system feature 🎉!