0

I have a situation where I want to be able to use an existing field from a class to satisfy an extension to the class that specifies a protocol. Something like this:

class SomeThing {
    var foo: String
}

protocol MyProtocol {
    var foo: String { get }
    func someOtherMethod()
}

extension SomeThing: MyProtocol {
    func someOtherMethod() {
    }
}

But the compiler is throwing errors in the file that defines the extension, that SomeThing doesn't fully conform to the protocol. Is there a way to make this work so that the extension just grabs the original object's value?

Kevin
  • 1,132
  • 2
  • 13
  • 24
  • 1
    Compiles fine for me after adding a `init(foo: String) {self.foo = foo}` to `SomeThing`. – Hamish Jul 12 '17 at 11:55
  • 1
    ... or by providing an initial value for the foo property. – A [mcve] and the full error message from the Report navigator would be helpful. – Martin R Jul 12 '17 at 12:09

0 Answers0