[swift-evolution] [Proposal draft] Remove objc requirement for optional protocol methods/properties

Matthew Johnson matthew at anandabits.com
Sat Jan 9 19:31:48 CST 2016


> On Jan 9, 2016, at 7:29 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On Jan 9, 2016, at 2:00 PM, David Scrève via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> ## Introduction
>> 
>> When using protocol, we usually need to use optional method or property. We propose to remove the 
>> requirement of @objc keyword for such protocol.
> 
> Hi David,
> 
> This is certainly a glaring hole in the system, and one we need to discuss.  Here are some problems with making optional requirements a first class thing in Swift:
> 
> 1. They overlap heavily (but are syntactically privileged) with optional properties, consider the difference between "optional func f() -> Int"  vs "var f : (() -> Int)?  {get}”.
> 
> 2. Protocols with default implementations provide the vastly most common use-cases for these.
> 
> 3. They overload “optional” terminology in the language to mean something different.
> 
> 4. They are non-sensical - how can something be a requirement and be optional? :)
> 
> 
> 
> Doug has it on his plate to explore what we can do about this, in the Swift 3 timeframe, but not in the immediate future.  IMO, it would be really great if we could make Objective-C optional requirements disappear in the Clang importer, and transform them into requirements with a default implementation.

+1 to this approach.

> 
> -Chris
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list