ios - 无法将类型“[()]”的返回表达式转换为返回类型
问题描述
我正在使用地图来更新所有数组值。但它返回一个空数组。
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
}
推荐阅读
- r - 来自字符向量内容的 R 数据帧
- c# - ABP 中带括号的权限 displayName
- android - 依赖服务.Get
不返回正确的实例 - kotlin - Is there a Kotlin-Multiplatform feature or pattern that can help to implement a common abstraction for, say, the Closeable interface?
- c# - MahApps.Metro Flyout 不覆盖列
- database - 用于存储多种奖励类型的用户成就/分数的数据库设计
- java - 试图从 JDBC 查询中获取返回码
- jquery - laravel refresh page and go to the correct tab after inserting record
- r - 使用对数变换使左偏分布正常?
- javascript - How do I write a JavaScript function that prints "Hello World" every 3rd time it is called?