Re: [swift-users] question on generics

2017-02-22 Thread Slava Pestov via swift-users

> On Feb 22, 2017, at 4:23 PM, David Sweeris via swift-users 
>  wrote:
> 
> 
>> On Feb 22, 2017, at 16:08, Dave Reed via swift-users  
>> 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 (i.e., the T must 
>> be both a NSManagedObject or subclass of it and conform to SomeProtocol).
>> 
>> Is this possible?
> 
> Yep
> class Foo  where T:  SomeProtocol {...}
> should work fine (although I'm not in front of my computer to double check)

Also this might be more readable,

class Foo where T : NSManagedObject, T : SomeProtocol { … }

Slava

> 
> - Dave Sweeris 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] question on generics

2017-02-22 Thread David Reed via swift-users
Cool thanks Kevin and David - I'll give it a try. 

> On Feb 22, 2017, at 7:20 PM, Kevin Nattinger  wrote:
> 
> This seems to work in a playground:
> 
> import CoreData
> 
> protocol SomeProtocol {}
> class Foo where T: SomeProtocol {}
> 
>> On Feb 22, 2017, at 4:08 PM, Dave Reed via swift-users 
>>  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 (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@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
> 
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] question on generics

2017-02-22 Thread David Sweeris via swift-users

> On Feb 22, 2017, at 16:08, Dave Reed via swift-users  
> 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 (i.e., the T must 
> be both a NSManagedObject or subclass of it and conform to SomeProtocol).
> 
> Is this possible?

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

- Dave Sweeris 
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] question on generics

2017-02-22 Thread Kevin Nattinger via swift-users
This seems to work in a playground:

import CoreData

protocol SomeProtocol {}
class Foo where T: SomeProtocol {}

> On Feb 22, 2017, at 4:08 PM, Dave Reed via swift-users 
>  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 (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@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] question on generics

2017-02-22 Thread Dave Reed via swift-users
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 (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@swift.org
https://lists.swift.org/mailman/listinfo/swift-users