[swift-evolution] [Proposal] Allow protocols to require functions with default parameter values.

肇鑫 owenzx at gmail.com
Sat Jan 16 04:15:52 CST 2016


No. Although you protocol's function doesn't has a default parameter value.
Your implementation does. So you don't need to define another func
function() in your protocol.

protocol Good {
    func printSomething(something:String)
}

struct Name:Good {
    func printSomething(something: String = "John") {
        print(something)
    }
}

Name().printSomething()

above code works.

zhaoxin

On Sat, Jan 16, 2016 at 6:05 PM, Vatsal Manot <vatsal.manot at yahoo.com>
wrote:

> It serves as a better (if not simpler) substitute for the following
> pattern:
>
> protocol Protocol
> {
>     typealias Argument
>
>     func function()
>     func function(_: Argument)
> }
>
>
> On 16-Jan-2016, at 3:29 PM, 肇鑫 <owenzx at gmail.com> wrote:
>
> I wonder where is the good for a protocol designer on this?
>
> zhaoxin
>
> On Sat, Jan 16, 2016 at 5:23 PM, Vatsal Manot via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> Currently, the following the code fails with multiple errors:
>>
>> protocol Protocol
>> {
>>     typealias Argument
>>
>>     func function(argument: Argument = default)
>> }
>>
>> I propose that we allow protocols to require functions with default
>> parameter values. I can’t see any disadvantages to this, and the change
>> would only be additive.
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>
>
>
> --
>
> Owen Zhao
>
>
>


-- 

Owen Zhao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160116/919ae8b1/attachment.html>


More information about the swift-evolution mailing list