小编Mun*_*han的帖子

FlatMap使用Int类型数组给出警告,但不使用String类型数组给出警告

当我flatMapString类型数组一起使用时,它没有给出任何警告,而在Int类型数组的情况下它给出了警告。为什么?例:

let strings = [
    "I'm excited about #SwiftUI",
    "#Combine looks cool too",
    "This year's #WWDC was amazing"
]
strings.flatMap{$0 + "."} //No warning

let ints = [
   2,3,4
]
ints.flatMap{$0 + 1} //'flatMap' is deprecated: Please use compactMap(_:) for the case where closure returns an optional value
Run Code Online (Sandbox Code Playgroud)

ios flatmap swift

4
推荐指数
1
解决办法
84
查看次数

标签 统计

flatmap ×1

ios ×1

swift ×1