Swift does not yet support common wildcard style patterns such as Java (i.e. Animal<?> ). Thus, the general pattern is to define a superclass, protocol (or shell) that is erased by type, to use such use instead. For instance:
public class AnyAnimal { }
and then use it as your superclass:
public class Animal<T: YummyObject>: AnyAnimal { ... }
Finally, use AnyAnimal instead of your non-generic code:
private static var animal: AnyAnimal!
Examples in the standard Swift library . For a practical example, see KeyPath , PartialKeyPath and AnyKeyPath class hierarchy. They follow the same pattern as I mentioned above. The collection structure provides even more examples of erasing styles, but uses a wrapper instead.
source share