swift - Cannot convert value of type 'Foo!' to expected argument type 'Foo!' -
i'm baffled i've run couple of times. errors similar following
cannot convert value of type 'foo!' expected argument type 'foo!
'
i've searched so, haven't found explains why foo! isn't same foo!.
here's example:
// fooviewmodel.swift class fooviewmodel: baseviewmodel { fileprivate var foo: foo! fileprivate var bar: bar = bar() init!(model: foo!) { super.init() foo = model } override init() { super.init() } func setfoomodel(_ model: foo!) { self.foo = model } func getfoomodel() -> foo! { return self.foo } func getbar() -> bar { return bar } func getblah() -> string { return "blah" } }
here unit test generates error:
import xctest @testable import woohoo class fooviewmodeltests: xctestcase { override func setup() { super.setup() } override func teardown() { super.teardown() } func testgetbar() { var foo = foo() let vm = fooviewmodel() // following line generates error vm.setfoomodel(foo) xctassertequal("tell foo bar program.", vm.getblah()) } }
i've tried number of variations vm.setfoomodel(foo)
no avail, e.g. vm.setfoomodel(foo!)
or declaring foo var foo: foo! = foo()
.
edit: note code above illustrating issue i'm running , not operational code.
i figured out. view model part of tests target. after set run target only, issue resolved. fyi.
Comments
Post a Comment