Wouldn't it be easier (syntax wise) to extend the meta type directly? :

protocol P {}
extension P.Type {
        static func a() {}
}

Kind regards
- Maximilian

> Am 28.02.2016 um 02:05 schrieb Joe Groff via swift-evolution 
> <[email protected]>:
> 
> Rasmus Kjeldsen via swift-evolution
> <[email protected]> wrote:
>> 
>> I propose to allow static protocol extension methods to be used directly on 
>> the protocol.
>> This would enable the Factory-pattern to be elegantly implemented as in the 
>> example below:
>> 
>> protocol P {}
>> 
>> class A : P {}
>> class B : P {}
>> 
>> extension P {
>>    static func factory(type: Bool) -> P { return type ? A() : B()}
>> }
>> 
>> let a = P.factory(false) // <- Not possible in Swift 2, factory() can
>> only be used on either A or B
>> 
>> Regards
>> 
>> Rasmus Friis Kjeldsen
> 
> 'extension P' extends all types that conform to P. We could introduce a new
> syntax for extending the protocol type, maybe:
> 
> extension protocol<P> { ... }
> 
> This might be an important part of fleshing out our support for protocol
> existential types. It would offer a way for protocol types to conform to
> their own protocols even when Self or associated types make that normally
> impossible. 
> 
> -Joe 
> 
> 
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to