Namespacing protocols to other types

Currently the best hack to allow nesting protocols inside of other types is to use a typealias. So given the common MyView.Delegate use-case, you could write something like:

protocol _MyViewDelegate: AnyObject {
}

struct MyView {
  typealias Delegate = _MyViewDelegate
}

class SomeDelegate: MyView.Delegate { // works!
}

But yeah, it would be a lot nicer if we could write that the way we write other nested types. I also still really want nested types in protocols.

9 Likes