swift map flatMap filter 用法

前端之家收集整理的这篇文章主要介绍了swift map flatMap filter 用法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
let numbers = [1,2,3,4]
        let result = numbers.map { $0 + 2 }
        let result2 = numbers.flatMap { $0 + 2 }
        print(result,result2)  // [3,4,5,6]
        let numbersCompound = [[1,3],[4,6]];
        let flatRes = numbersCompound.flatMap { $0.map{ $0} }
        let filteredArray = flatRes.filter({$0 > 5})

猜你在找的Swift相关文章