Custom equality in swift objects preserving compatibility with legacy Objective-C code

Yes, you need to override isEqual (and hash) to make your objects fully Objective-C compatible. Here’s a Playground-ready example for the syntax: import Foundation class MyClass: NSObject { var value = 5 override func isEqual(object: AnyObject?) -> Bool { if let object = object as? MyClass { return value == object.value } else { return … Read more

Comparing boxed value types

If you need different behaviour when you’re dealing with a value-type then you’re obviously going to need to perform some kind of test. You don’t need an explicit check for boxed value-types, since all value-types will be boxed** due to the parameter being typed as object. This code should meet your stated criteria: If value … Read more

Overriding the == operator in Ruby

In Ruby == is just a method (with some syntax sugar on top allowing you to write foo == bar instead of foo.==(bar)) and you override == just like you would any other method: class MyClass def ==(other_object) # return true if self is equal to other_object, false otherwise end end

Java: How to test on array equality?

Why is the following code printing “Different.”? Because Arrays.equals performs a shallow comparison. Since arrays inherit their equals-method from Object, an identity comparison will be performed for the inner arrays, which will fail, since a and b do not refer to the same arrays. If you change to Arrays.deepEquals it will print “Equal.” as expected.

Implementing -hash / -isEqual: / -isEqualTo…: for Objective-C collections

I think trying to come up with some generally useful hash function that will generate unique hash values for collections is an exercise in futility. U62’s suggestion of combining the hashes of all the contents will not scale well, as it makes the hash function O(n). Hash functions should really be O(1) to ensure good … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)