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 function See 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
keyword To resolve these issues, use this instead:
override var hash : Int {
return /* (your hash logic) */
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.