Swift 之数组过滤 filter 方法
func findEmoticon(string: String) -> CZEmoticon? {
//
for p in packages {
// 1
//let result = p.emoticons.filter({ (em) -> Bool in
// return em.chs == string
//})
// 2
//let result = p.emoticons.filter() { (em) -> Bool in
// return em.chs == string
//}
// 3
//let result = p.emoticons.filter() {
// return $0.chs == string
//}
// 4
let result = p.emoticons.filter() { $0.chs == string }
//
if result.count == 1 {
return result[0]
}
}
return nil
}
本文标题:Swift 之数组过滤 filter 方法
本文链接:https://www.haomeiwen.com/subject/tyhzfftx.html
网友评论