swift2 - compare two generic objects on swift 2.0 -


i have establish whether current value equal given comparing value.

public static func is<tbasevalue, tcomparingvalue>(basevalue: tbasevalue, comparingvalue: tcomparingvalue) -> bool {     return basevalue == comparingvalue } 

i try

public static func is<tbasevalue: comparable, tcomparingvalue: comparable>(basevalue: tbasevalue, comparingvalue: tcomparingvalue) -> bool {     return basevalue==comparingvalue } 

and this

  public static func is<tbasevalue: equatable, tcomparingvalue: equatable>(basevalue: tbasevalue, comparingvalue: tcomparingvalue) -> bool {     return basevalue == comparingvalue } 

but have same result binary operator cannot applied....

equatable doesn't mean that. think things equatable - int, instance. 2 == 2 makes sense. 2 == 3 return false - still makes sense. now, think of else that's equatable - string, instance.

"abc" == "abc" // true "acb" == "abc" // false 

that's fine - this:

"abc" == 4 

an equatable thing equatable - not else. in example, you're comparing 2 different types - tbasevalue, tcomparingvalue.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -