[英]Cannot convert return expression of type '[()]' to return type
我正在使用 map 来更新所有数组值。 但它返回一个空数组。
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]'
您必须显式返回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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.