My code was supporting Swift 3.3 before, now I'm upgrading it to Swift 4.1 using Xcode 9.3. It shows me the following error while trying to build my project.
Here is code for JSON parsing
// MARK: Store JSON initializer
convenience init?(withJSON json: JSON) {
//json mapping
//This is of type [Character] after mapping
let services = json["services"].arrayValue.flatMap({ $0 }).flatMap({ $0.1.stringValue }) //Convert response to 1D array and convert it to array if String
}
Here is that init method which I'm trying to call
//Custom init method
init(id: Int, storeNumber: String, title: String, location: Location, type: String, zip: String, parent: Int, city: String, services: [String], state: String, storePhone: [String], pharmacyPhone: [String], pharmacyFax: [String], workingHours: WorkingHoursString) {
//field with error
//here self.services is of type [String]
self.services = services
}
I'm using pod 'SwiftyJSON', '3.1.4' For Json parsing.
Error - Cannot convert value of type '[character]' to expected argument type '[String]'
/* JSON for services is as given
"services":[
[
"Fresh Food"
]
]
*/
print("Services are \(services)")
Services are ["F", "r", "e", "s", "h", " ", "F", "o", "o", "d"]
What could be the simplest solution to fix this?