我正在使用地图更新所有数组值。但是它返回的是一个空数组。
var filterProductList = [CategoryProduct]()
let finalList = filterProductList.map{ p in
if let pf = test.rankings[0].products.first(where: {$0.id == p.id}) {
p.rankCount = pf.viewCount
}
}
return finalList // Showing error here cannot convert return expression of type '[()]' to return type '[CategoryProduct]'
答案 0 :(得分:3)
您必须显式返回p
并指定返回类型
let finalList = filterProductList.map{ p -> CategoryProduct in
if let pf = test.rankings[0].products.first(where: {$0.id == p.id}) {
p.rankCount = pf.viewCount
}
return p
}