加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift:无法使用类型'(@noescape(Int)throws – > Bool)

发布时间:2020-12-14 04:30:37 所属栏目:百科 来源:网络整理
导读:我遇到了这个错误: func compactCoords(coords: [Int]) - [Int]{ return coords.filter({ (value) - Bool in return value != 0 })} 无法使用类型为'(@noescape(Int)throws – Bool)’的参数列表调用’filter’ 谢谢你的帮助! 解决方法 您的代码在Xcode 7.
我遇到了这个错误:

func compactCoords(coords: [Int]) -> [Int]{
    return coords.filter({ (value) -> Bool in
        return value != 0
    })
}

无法使用类型为'(@noescape(Int)throws – > Bool)’的参数列表调用’filter’

谢谢你的帮助!

解决方法

您的代码在Xcode 7.1中运行良好.您可能不小心尝试在Xcode 6.x中运行此代码?

你可以像这样缩短你的功能:

func compactCoords(coords: [Int]) -> [Int] {
    return coords.filter { $0 != 0 }
}

输出:

let coords = [1,2,3,4,5,6]
let compactedCoords = compactCoords(coords) // [1,6]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读