[swift-users] question on generics

Kevin Nattinger swift at nattinger.net
Wed Feb 22 18:20:33 CST 2017

This seems to work in a playground:

import CoreData

protocol SomeProtocol {}
class Foo<T: NSManagedObject> where T: SomeProtocol {}

> On Feb 22, 2017, at 4:08 PM, 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?
> Thanks,
> Dave Reed
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170222/0b4aef90/attachment.html>

More information about the swift-users mailing list