Harsha Harsha -4 years ago 106
Swift Question

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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download