[swift-evolution] Proposal: Change of syntax for class protocols

Joe Groff jgroff at apple.com
Mon Dec 7 15:05:39 CST 2015


> On Dec 7, 2015, at 12:49 PM, Guillaume Lessard via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On 7 déc. 2015, at 09:58, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> The constraint syntax is used because, in the fullness of time, it should also be applicable to type parameters and associated types:
>> 
>> protocol Foo { typealias T: class }
>> 
>> func foo<T: class>(x: T)
> 
> Is using the AnyObject protocol significantly less desirable in those cases?
> 
> (It may be that you consider AnyObject to be a workaround…)

Yeah, ': AnyObject' is more or less a workaround for ': class' not working. AnyObject should be just a typealias for the protocol<class> type.

-Joe


More information about the swift-evolution mailing list