bemeyer
bemeyer

Reputation: 6231

Value of type '...' does not conform to '...' in assignment

In a project we are facing a weird problem with prodocols not get picked up by xcode.

We defined the following protocol within the regular app:

protocol VCDismisser: class {
    func dismiss(animated: Bool, completion: (() -> Void)?)
}

extension UIViewController: VCDismisser {}

Within a random ViewController we define:

class RandomVC: UIViewController {
   lazy var vcDismisser: VCDismisser = self
}

Within a test part of the XCProject we want define the following:

class MockDismisser: VCDismisser {
    var dismissCalled = false
    func dismiss(animated: Bool, completion: (() -> Void)?) {
        dismissCalled = true
    }
}

And in any testcase for the RandomVC we want to "inject" our mock:

func testSuccessfulLoginDismisses() {
    let dismisser = MockDismisser()
    randomVC.vcDismisser = dismisser
    randomVC.viewDidLoad()
    mockviewModel.loggedIn.value = LoginState.successful
    XCTAssertTrue(dismisser.dismissCalled)
}

XCode is now getting pretty bonkers and always tells us:

enter image description here

What do we do wrong here and how do we fix that xcode is accepting it as the right type?

Upvotes: 2

Views: 1726

Answers (2)

bemeyer
bemeyer

Reputation: 6231

The reason here was something which wasn't obvious within my question. The File containing the extension and the protocol had the target membership of test and the application causing xcode getting confused. Removing the target membership of test did resolve the issue.

Upvotes: 4

Kristijan Delivuk
Kristijan Delivuk

Reputation: 1252

Try to cast Mock dissmisser as VCDismisser:

let dismisser: VCDismisser = MockDismisser()

Upvotes: -1

Related Questions