0

I've created a small example. I want that localizedString() invokes in SomeError enum. But I see that this method all time invokes in extension. Wham am I doing wrong. Hope someone can solve my problem.

extension Error {
    func localizedString() -> String {
        return "extension"
    }
}

enum SomeError: Error {
    case test
    func localizedString() -> String {
        return "SomeError"
    }
}

func print(error: Error) {
    error.localizedString()
}

print(error: SomeError.test)
Nikita Ermolenko
  • 2,139
  • 2
  • 19
  • 41
  • 1
    Is this what you are looking for? – [How to provide a localised description with an Error type in Swift?](http://stackoverflow.com/questions/39176196/how-to-provide-a-localised-description-with-an-error-type-in-swift) – Martin R Nov 14 '16 at 13:51
  • Your approach does not work because the method is *statically* dispatched. See this comment http://stackoverflow.com/questions/39509399/error-protocol-in-swift?noredirect=1&lq=1#comment66337865_39509399 to a similar question, and http://stackoverflow.com/questions/31431753/swift-protocol-extensions-overriding or http://stackoverflow.com/questions/39007960/override-of-protocol-default-implementation-in-a-subsubclass-doesnt-participate/39008193#39008193 for more details. – Martin R Nov 14 '16 at 13:57

0 Answers0