Remove matched item from array of objects?

前端 未结 4 1384
感动是毒
感动是毒 2020-12-11 17:56

I have an array of objects like this:

var myArr = [
  MyObject(name: \"Abc\", description: \"Lorem ipsum 1.\"),
  MyObject(name: \"Def\", description: \"Lore         


        
4条回答
  •  -上瘾入骨i
    2020-12-11 18:44

    Get the objects using filter then loop through the array and use myArr.removeAtIndex(index) to remove each object. Using filter is doing exactly that. To understand what is happening read below. Matts answer is a much cleaner way to accomplish this since you're testing for the opposite match therefore each object is preserved unless it matches your value.

    Loop through your temp filter array

    if let index = find(temp, note) {
       myArr.removeAtIndex(index)
    }
    

提交回复
热议问题