I have a subclass of PFUser - MYUser class with implementation of Equatable function for comparing objectIds this way:
func ==(left: MYUser, right: MYUser) -> Bool {
return left.objectId == right.objectId
}
But when I call Array.contains() method it doesn't call this implementation of Equatable function, that leads to incorrect results. For instance, here:
let hasUser = self.selectedUsers.contains(currentUser)
hasUser becomes false if selectedUsers array contains different memory object but with the same objectId as in currentUser.
What interesting, Equatable function implementation is called in direct usage. Here:
var hasUser = false
for itUser in self.selectedUsers {
if itUser == currentUser {
hasUser = true
break
}
}
== operator successfully was called and hasUser has correct values for different memory objects but with the same objectId
What can be the cause of it?
UPDATE. Here is MYUser class:
class MYUser: PFUser {
// MARK: - Parse Object
@NSManaged var avatarFile: PFFile?
@NSManaged var fullName: String?
// MARK: - PFSubclassing Methods (through PFUser)
override class func initialize() {
struct Static {
static var onceToken : dispatch_once_t = 0;
}
dispatch_once(&Static.onceToken) {
self.registerSubclass()
}
}
}
func ==(left: MYUser, right: MYUser) -> Bool {
return left.objectId == right.objectId
}
isEqual:
instead of==
. – Wofford==
for subclass isn't called incontains
. – MosquedaMYUser
is defined? – Photocurrent