Swift filter array of objects

前端 未结 7 960
忘了有多久
忘了有多久 2021-02-03 20:44
class book{
    var nameOfBook: String!
}

var englishBooks=[book(),book(),book()]
var arr = englishBooks.filter {
    contains($0.nameOfBook, \"rt\")
}
<
7条回答
  •  悲哀的现实
    2021-02-03 21:08

    I think this is more useful for lack of wrong typing situation.

    englishBooks.filter( { $0.nameOfBook.range(of: searchText, options: .caseInsensitive) != nil}
    

提交回复
热议问题