mercredi 13 décembre 2017

In Swift, can you find all types in a module that adhere to a specific protocol?

In Swift 4, is it possible to find all types within the current module which adhere to a specific protocol?

For instance, say I've defined this protocol and these classes:

protocol Animal{}
protocol Vehicle{}
protocol Favorite{}

class Dog : Animal{
}

class Cat : Animal, Favorite{
}

class Car : Vehicle{
}

class Bicycle : Vehicle, Favorite{
}

I want to find all types that implement Favorite.

  • Cat
  • Bicycle

If it helps, I'm using Swift 4.





Aucun commentaire:

Enregistrer un commentaire