Я столкнулся с проблемой ниже в Swift 4.2 с Xcode 10
Я создаю все классы моделей. Ответ API содержит этот тип объекта JSON:
{
"d":{
"results":[
{
"__metadata":{
"id":"urls"
}
}
]
}
}
Как я могу создавать классы с тем же именем без двусмысленности?
Вот моя реализация класса:
import Foundation
import Alamofire
class SearchPINModel: Codable {
let d: D?
init(d: D?) {
self.d = d
}
}
class D: Codable {
let results: [Result]?
init(results: [Result]?) {
self.results = results
}
}
class Result: Codable {
let metadata: Metadata?
let sapID, deviceID, mobileNo, employeeName: String?
let pincode, sapUser, deviceCode: String?
enum CodingKeys: String, CodingKey {
case metadata = "__metadata"
case sapID = "SapId"
case deviceID = "DeviceId"
case mobileNo = "MobileNo"
case employeeName = "EmployeeName"
case pincode = "Pincode"
case sapUser = "SapUser"
case deviceCode = "DeviceCode"
}
init(metadata: Metadata?, sapID: String?, deviceID: String?, mobileNo: String?, employeeName: String?, pincode: String?, sapUser: String?, deviceCode: String?) {
self.metadata = metadata
self.sapID = sapID
self.deviceID = deviceID
self.mobileNo = mobileNo
self.employeeName = employeeName
self.pincode = pincode
self.sapUser = sapUser
self.deviceCode = deviceCode
}
}
class Metadata: Codable {
let id, uri: String?
let type: String?
init(id: String?, uri: String?, type: String?) {
self.id = id
self.uri = uri
self.type = type
}
}