Implement method from protocol of superclass that uses default implementation

Hi all,
So there is a simple example that works as I expect:

protocol AProtocol {
    func a()
    func start()
}

extension AProtocol {
    func a() {
        print("A")
    }

    func start() {
        a()
    }
}

class A: AProtocol {
    func a() {
        print("A")
    }
}

class B: A {
    override func a() {
        print("B")
    }
}

B().start()

... prints B

Now I want class A to use default implementation of 'a' method:

protocol AProtocol {
    func a()
    func start()
}

extension AProtocol {
    func a() {
        print("A")
    }

    func start() {
        a()
    }
}

class A: AProtocol {
}

class B: A {
    func a() {
        print("B")
    }
}

B().start()

...prints A

What should I do to use method from B instead?

This is an issue that's been around for a few years, you can see the bug report here: https://bugs.swift.org/browse/SR-103

Thank you, maybe you know a good solution for this situation for now?
Also I missed one detail - in class B I want to use default AProtocol method a() + do something else
So for now I do:

protocol AProtocol {
    func a()
    func aDefault()
    func start()
}

extension AProtocol {
    func start() {
        a()
    }

    func aDefault() {
        print("A")
    }
}

class A: AProtocol {
    func a() {
        aDefault()
    }
}

class B: A {
    override func a() {
        aDefault()

        print("Do some other things")
    }
}

B().start()
Terms of Service

Privacy Policy

Cookie Policy