I got this error message since update 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_);
}
To elaborate: @property(readonly) NSUInteger hash
is an Objective-C property of NSObject
, that means there is a getter created for that variable, namely hash()
.
You now try to define a method of the same name and the same parameters (none) but with a different return type (UInt
instead of NSUInteger
, which would be Int
in swift.). Therefore you receive the given error. To resolve that issue you have two options now:
Int
-> that will override the predefined hash functionSee the NSObjectProtocol
declaration, where hash
is declared:
var hash: Int { get }
You have three problems:
hash
is a var
, not a func
Int
, not UInt
.override
keywordTo resolve these issues, use this instead:
override var hash : Int {
return /* (your hash logic) */
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With