[swift-users] Identity based object hash?

Travis Griggs travisgriggs at gmail.com
Wed Oct 5 11:53:54 CDT 2016


I have a class that I’d rather not have based off of NSObject, but I do want to have identity based equality. I’ve done that as follows:

class Foobar { }

extension Foobar:Equatable { }

func == (a:Foobar, b:Foobar) -> Bool {
	return a === b
}

What’s less clear to me is how to go about implementing an identity based hash

extension Foobar:Hashable {
	var hashValue:Int {
		// what magic should happen here?
	}
}


More information about the swift-users mailing list