当我flatMap与String类型数组一起使用时,它没有给出任何警告,而在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)