[swift-users] question on generics

David Reed davelist at mac.com
Wed Feb 22 20:09:21 CST 2017


Cool thanks Kevin and David - I'll give it a try. 

> On Feb 22, 2017, at 7:20 PM, Kevin Nattinger <swift at nattinger.net> wrote:
> 
> 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/01e6fefb/attachment.html>


More information about the swift-users mailing list