nyitguy nyitguy - 1 year ago 135
Swift Question

Swift arrays of strings

I have an array of strings.

var animals = ["cats 99", "dogs 42", "chimps 45", "moose 98"]
var excludeAnimalArray = ["chimps", "dogs"]

Output should be "cats 99", "moose 98". Please keep in mind there is no way to tell what the number next to the animal will be.

Answer Source

A shorter filter:

let result = animals.filter { animal in
    !excludeAnimalArray.contains { animal.hasPrefix($0) }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download