Swift - the '* ()' method with the Objective-C selector '*' conflicts with the getter for '*' from the 'NSObject' superclass with the same Objective-C selector

I got this error message since upgrading my xcode to 6.3.1.

/Users/MNurdin/Documents/iOS/xxxxx/Models/Message.swift:46:10: Method 'hash()' with Objective-C selector 'hash' conflicts with getter for 'hash' from superclass 'NSObject' with the same Objective-C selector

My code

var hash_ : UInt

func hash() -> UInt {
        return UInt(hash_);
    }
+4
source share
2 answers

To clarify: @property(readonly) NSUInteger hash- this is an Objective-C property NSObject, this means that a getter has been created for this variable, namely hash().

Now you are trying to define a method with the same name and the same parameters (none), but with a different return type ( UIntinstead of NSUIntegerwhat will be Intin swift.). Therefore, you get this error. To solve this problem, you have two options:

  • Int → , -
+4

. NSObjectProtocol, hash :

var hash: Int { get }

:

  • hash - var, func
  • Int, UInt.
  • override

, :

override var hash : Int {
    return /* (your hash logic) */
}
+4

All Articles