Wie implementieren Sie Protokollmethoden, die kovariante Selfs zurückgeben?

error: Protokoll 'Protokoll' Anforderung 'Instanz' kann von einer nicht endgültigen Klasse ('Klasse') nicht erfüllt werden, da 'Self' in einer Position ohne Parameter und ohne Ergebnistyp verwendet wird.

protocol Protocol {
    var instance: Self {get}
}

class Class: Protocol {
    var instance: Class {return Subclass()}
}

class Subclass: Class {}

Hier ist, wie ich in C # ausdrücken würde, was ich will. (Meines Wissens hat C # keine Möglichkeit zu erzwingen, dass der generische Parameter "Self" tatsächlich das Self ist, das wir von Swift kennen, aber es funktioniert gut genug als Dokumentation, die mich dazu bringen sollte, das Richtige zu tun.)

interface Protocol<Self> where Self: Protocol<Self> {
    Self instance {get;}
}

class Class: Protocol<Class> {
    public Class instance {get {return new Subclass();}}
}

class Subclass: Class {}

… Wie das in einer zukünftigen Version von Swift aussehen könnte:

protocol Protocol {
    typealias FinalSelf: Protocol where FinalSelf.FinalSelf == FinalSelf

    var instance: FinalSelf {get}
}

class Class: Protocol {
    var instance: Class {return Subclass()}
}

class Subclass: Class {}

Wie ich den Teil emuliere, der für mein Problem relevant ist:

protocol Protocol: ProtocolInstance {
    static var instance: ProtocolInstance {get}
}

protocol ProtocolInstance {}


class Class: Protocol {
    static var instance: ProtocolInstance {return Subclass()}
}

class Subclass: Class {}

Und hier ist, was ich für den relevanten Teil meines Codes halte:

protocol Protocol {
    static var : Self? {get} // an existing instance? 
    static var : Self {get}  // a new instance

    func instanceFunc()
}

extension Protocol {
    static func staticFunc() {
        ( ?? ).instanceFunc()
    }
}

Antworten auf die Frage(4)

Ihre Antwort auf die Frage