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) }) }
// The first $0 is from the filter and it represents each User.
// The second $0 is from the first contains and it represents each pet within the pets array of the current User.
Also in Swift:
- how to show notification icon on tabbar item swift
- swift image button blue
- remove child from firebase swift
- hide bottom tab bar swift
- get item filter count swift
- swift sort array
- swift set uicolor
- swift how to add a completion block to a function
- deselect all cell in collectionview
- swift add horizontal line uiview programmatically
- swift change enum value
- swift uitextfield only numbers keyboard lock programmatically
- swift remove tableview cell
- how to swift pie chart quartzcore framework
- swift wait 5 seconds
- one line if statement swift
- how to screen record swift stackoverflow
- swift get day from available string
- switch statements swift
- swift uitableview cell spacing
- fnb swift code
- guard let swift
- how to set the center in view in swift
- swiftui font color