Tom
Tom

Reputation: 4033

Filter array for all structs with specific name and remove them

I have an array carsArray of structs - each struct has a name. A name might be used several times inside of this array.

Let's say I have a car called "Audi" - how can I filter the given array of structs and delete every entry with the name "Audi" ?

Upvotes: 0

Views: 41

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100503

Model

struct Car {
   let name:String
}

Filter & Remove all items with a specific criteria

var arr = [Car]()
// fill the array here
arr.removeAll(where:{ $0.name == "Audi" })

Upvotes: 1

Related Questions