I have an array of custom objects, a.k.a users, and some of them are duplicates.
How can I make sure there is only one of each element? No duplicates.
Also, what's the most efficient way?
var users: UserModel = [UserModel]()
I have an array of custom objects, a.k.a users, and some of them are duplicates.
How can I make sure there is only one of each element? No duplicates.
Also, what's the most efficient way?
var users: UserModel = [UserModel]()
Most efficient way if you don’t care about maintaining the original order in the array
let uniqueUsers = Array(Set(users))
Maybe instead of using an array you want to use a set? https://developer.apple.com/documentation/swift/set