0

I have a protocol:

protocol ApiEndpointsProtocol {
    func getKey(for endpoint: API.Keys, withChar: Bool) -> String
}

and I want to initialize withChar to be always true if no value is provided, this is my attempt:

extension ApiEndpointsProtocol {
    func getKey(for endpoint: API.Keys, withChar: Bool = true) {
        getKey(for: endpoint, withChar: withChar)
    }
}

But I'm getting a warning on the function call: getKey(for: endpoint, withChar: withChar)

Result of call to 'getKey(for:withChar:)' is unused

What's the right approach to do this?

Here's a screenshot:

enter image description here

enter image description here

Albert
  • 99
  • 7
  • Whoever marked that question as duplicate, that one is using a completion handler and has no mention of what I'm talking about of the function not being used, please be mindful. – Albert Oct 25 '22 at 13:00
  • The required function in the protocol has a `-> String` return value, but as the warning states it's unused. – vadian Oct 25 '22 at 13:04
  • I understand what it says, how can I fix it? I'm using it when I call the protocol itself, but what does it has to do with defining it? @vadian – Albert Oct 25 '22 at 13:05
  • You have to add `-> String` also in the extension. But the function is pointless as you can specify a default value anyway. – vadian Oct 25 '22 at 13:08
  • Yes, that fixed it. I didn't try that again because I had try it at the beginning and didn't work. Thank you @vadian – Albert Oct 25 '22 at 13:10

0 Answers0