struct Response: Codable {
let status: String
let value: [Value]
}
struct Value: Codable {
let psid: Int
let name: String
let valute: String
let reserve: Double
let with_codes: Int
let img: String
}
var good = [Value]()//first array
struct Response1: Codable {
let status: String
let value: [Value1]
}
struct Value1: Codable {
let id: String
let enabled: Int
let direct: Int
let psid1: Int
let psid2: Int
let in: Int
let in_valute: String
let out: Double
let out_valute: String
let in_min: Double
let in_max: Int
let reserve: Double
}
var good1 = [Value1]()//second array
good.forEach { goodItem in
if good1.contains(where: { good1Item -> Bool in
return good1Item.psid2 == goodItem.psid
}) {
print(goodItem)
}
}
问题是,当我需要将goodItem.name输出到表时,只输出最后一个值,虽然当我检查控制台中的所有内容时,google我发现return方法只返回最后一个值,怎么能我解决了吗?
答案 0 :(得分:0)
这对我有用:
for value in good {
if good1.filter( {$0.psid2 == value.psid}).count > 0 {
print(value.name)
}
}