Search code examples
iosswiftswifty-jsonxcode7.3swift2

Cannot convert value of type 'JSON' to expected argument type 'JSON'


Below is the code,

//Controller.swift
struct MyObject {
    init(myJson: JSON) {
    // some code here
    }
}

//unittest.swift
let json = JSON("{}")
let obj = MyObject(myJson: json)

I get the error Cannot convert value of type 'JSON' to expected argument type 'JSON'

Note: However, this does not happen when I put the struct in the same unit test file. Using SwiftyJSON library for JSON parsing


Solution

  • After banging my head for several hours found out that issue was due to including SwiftyJSON file for both app and test targets.