Swift 之数组过滤 filter 方法
2018-03-13 本文已影响0人
willokyes
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
}