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

Riley Testut rileytestut at gmail.com
Mon Dec 7 13:36:24 CST 2015


Yes, whenever I implement the delegate pattern, I have to make sure the protocol is a class protocol so I can use a weak reference. 

While I use protocols for far more than just delegation, for the newer developers coming to Swift from Objective-C, the delegation pattern probably remains the most common use of protocols, so I agree we should make it as simple to use/understand as possible. +1 for the proposed syntax.

> On Dec 7, 2015, at 9:20 AM, Matthew Cheok via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I would expect this to be somewhat common for building weakly referenced delegates without @objc. Shouldn't this be more common in practice?
> 
> On Mon, Dec 7, 2015 at 8:51 AM, Stephen Celis <stephen.celis at gmail.com <mailto:stephen.celis at gmail.com>> wrote:
> Do others find themselves implementing class-only protocols often? They seem to be the exception, rather than the rule, to me.
> 
> Stephen
> 
> On Mon, Dec 7, 2015 at 11:32 AM, Sean Heber via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> I found this odd, too. I don’t know what kind of parsing ramifications this might have, but I like the idea. I suppose one downside is that it makes protocols for classes seem somehow special or different from other protocols - but then again, they kind of are!
> 
> l8r
> Sean
> 
> 
> > On Dec 7, 2015, at 10:00 AM, Matthew Cheok via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> >
> > Currently, we declare class protocols with the following syntax:
> >
> > protocol TestProtocol: class, OtherProtocol {}
> >
> > This is odd for a few reasons:
> > 1) The keyword class exists in the middle of the declaration
> > 2) The keyword class follows the colon and looks a lot like inheritance
> > 3) The keyword class occupies a somewhat arbitrary first position after the colon (otherwise we have an error)
> >
> > We also have another use of the class keyword as a modifier when declaring class methods:
> >
> > class func doSomething() {}
> >
> > I’m suggesting a change of syntax that rectifies the above issues:
> >
> > class protocol TestProtocol: OtherProtocol {}
> >
> > Would love to hear other thoughts on this.
> >
> > - Matthew
> >
> > _______________________________________________
> > swift-evolution mailing list
> > swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> > https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> 
>  _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151207/cb87730b/attachment.html>


More information about the swift-evolution mailing list