Cant make equatable extension for PFObject

Hi

I think swift 2 gives an error for this code

extension PFObject : Equatable { }

public func ==(lhs: PFObject, rhs: PFObject) -> Bool {
      return lhs.objectId == rhs.objectId
}


The error I m receiving : Redundant conformance of 'PFObject' to protocol 'Equatable'


I m trying to perform equatable for PFObject but this line gives error.

Any solution?


Thank you

You're probably getting this error because a class which PFObject inherits from already conforms to Equatable.


Since protocol conformance is inherited, you can't declare that protocol conformance again in a subclass, but you can override non-final methods required by the protocol or provide more specifically typed versions of operators.


Generally, the most specific version available of overloaded functions will be used by the compiler (based on how the objects are typed in the calling code), so your implementation of == would be used for two instances typed as PFObject, rather that the parent class's version.

Hi. Thanks for the reply. I m new to Swift Programming.


Can you give me an example on onverriding the current equatable method for pfobject? I tried to find examples online but wasn't able to solve it.


Thank you

The version of the == function in your original post is all you need to do, for the compiler to use that version when it knows it is dealing with two PFObject instances.


This is called overloading the operator, and is described in more detail in the Swift language docs here:

https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AdvancedOperators.html#//apple_ref/doc/uid/TP40014097-CH27-ID42


Once you remove the extra declaration of PFObject conforming to Equatable, your code should compile and work.

Cant make equatable extension for PFObject
 
 
Q