Swift filter array of objects

前端 未结 7 958
忘了有多久
忘了有多久 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:28

    In Swift 4.2 use the remove(where:) functionality. filter isn't doing well with memory, remove(where:) does the job better.

    To do what you want:

    englishBooks.removeAll { !$0.nameOfBook.contains("English") }
    

提交回复
热议问题