Swift filter array of strings

后端 未结 4 2067
日久生厌
日久生厌 2021-02-20 15:49

I\'ve had troubles filtering array of keywords (strings) in swift ,My code:

self.filteredKeywords=filter(keywords.allValues, {(keyword:NSString) ->                    


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-20 16:16

    Swift 4.2 provides a new way to do this:

    var theBigLebowski = ["The Dude", "Angry Walter", "Maude Lebowski", "Donny Kerabatsos", "The Big Lebowski", "Little Larry Sellers"]
    
    // after removeAll -> ["The Dude", "Angry Walter", "Donny Kerabatsos", "Little Larry Sellers"]
    theBigLebowski.removeAll{ $0.contains("Lebowski")}
    print(theBigLebowski)
    

提交回复
热议问题