2

setsOfCardsByLevel is an array of cards.
Every card has a level.
I want to remove all cards from array if their level is equal to level from the parameter. Here is my function:

 func removeCardsByLevel(_ level: Int) {
            for card in setsOfCards {
                if card.level == level {
                    setsOfCards.remove // HOW?
                }
              }
          }

Advices? Ideas?

faris97
  • 402
  • 4
  • 24

1 Answers1

4

If I understand you correctly, you wish to remove the cards that matches a certain level?

setsOfCards.removeAll { $0.level == level } 
Roman Podymov
  • 4,168
  • 4
  • 30
  • 57
rodskagg
  • 3,827
  • 4
  • 27
  • 46