美文网首页
Swift 之数组过滤 filter 方法

Swift 之数组过滤 filter 方法

作者: willokyes | 来源:发表于2018-03-13 13:05 被阅读0次
    
        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