swift filter array code example
Example 1: swift filter array
var users: [User] = []
users.append(User(name: "testUset", age: 43, hasPet: true, pets: ["cat", "dog", "rabbit"]))
users.append(User(name: "testUset1", age: 36, hasPet: true, pets:["rabbit"]))
users.append(User(name: "testUset2", age: 65, hasPet: true, pets:["Guinea pigs", "Rats"]))
let petArr = ["cat", "dog", "rabbit"]
users = users.filter { $0.pets.contains(where: { petArr.contains($0) }) }
Example 2: swift filter array
let petArr = ["cat", "dog", "rabbit"]