I've got an array of Profile's (defined from a custom struct), and inside this, I have a [String] of interests.
I want to filter out any profiles which don't match an array of preferences, but can't seem to get my filtering to work.
The error I get is
"Cannot convert value of type '[String]' to expected argument type 'String'.
What am I missing?
Once complete, I'd expect userProfiles to contain only John and Harry.
struct Profile {
var name: String
var interests: [String]
}
var userProfiles: [Profile] = [
Profile(name: "John", interests: ["Basketball", "Football", "Rowing"]),
Profile(name: "Andrew", interests: ["Cycling", "Swimming", "Boxing"]),
Profile(name: "Harry", interests: ["Hockey", "Baseball"])
]
let preferenceInterests = ["Basketball", "Hockey"]
userProfiles = userProfiles.filter({ (userProfile) -> Bool in
print("\(userProfile.name): \(userProfile.interests)")
return preferenceInterests.contains(userProfile.interests) //error here
})