Duc Ninja

Swift 4 - Class only protocol

We usually use the class keyword to define a class only protocol in the normal way.

protocol DetailViewControllerDelegate: class {
  func didFinishTask(sender: DetailViewController)
}

Since Swift 4, we have an other way to define it. Introduced in 0156-subclass-existentials

This proposal merges the concepts of class and AnyObject, which now have the same meaning: they represent an existential for classes.

So, it much clearer with the new way:

protocol DetailViewControllerDelegate: AnyObject {
  func didFinishTask(sender: DetailViewController)
}

Happy coding!