dimanche 9 août 2020

Pattern matching generic types… well… generically

I'm trying to use reflection to dynamically read all properties in a class, and then switch upon each property to detect its type. Sadly, I'm not sure how to do this, as the Swift compiler keeps throwing errors.

Here's an example of what I would like to achieve:

class Property<SpecialKey, Value> where SpecialKey: Codable, Value: Codable { … }

class CustomProperty: Property { … }

switch CustomProperty() {
case is Property: // Requires that I specify the generics, e.g.: Property<String, String>. I just want to match Property<T, U>, where T: Codable and U: Codable.
  break
default:
  break
}

Thanks in advance for any assistance.





Aucun commentaire:

Enregistrer un commentaire