[swift-users] question on generics

David Sweeris davesweeris at mac.com
Wed Feb 22 18:23:12 CST 2017


> On Feb 22, 2017, at 16:08, Dave Reed via swift-users <swift-users at swift.org> wrote:
> 
> I suspect this can't be done (at least not right now), but wanted to check.
> 
> I'd like to declare a class as a generic that meets a protocol and is also a subclass of some specific type.
> 
> Something like class Foo<T:NSManangedObject,SomeProtocol> (i.e., the T must be both a NSManagedObject or subclass of it and conform to SomeProtocol).
> 
> Is this possible?

Yep
class Foo <T: NSManangedObject> where T:  SomeProtocol {...}
should work fine (although I'm not in front of my computer to double check)

- Dave Sweeris 


More information about the swift-users mailing list