Identity comparison of generics in Swift -


i'm wondering if , how identity comparison of instances of generic class. example:

class foo<t> {   let a: t   let b: t    init(a: t, b: t) {     self.a =     self.b = b   }    func isidentical() -> bool {     return === b   } } 

doing giving me error @ compile-time:

binary operator '===' cannot applied 2 t operands

this should works:

class foo<t: anyobject> { //         ^^^^^^^^^^^ added     let a: t     let b: t      init(a: t, b: t) {         self.a =         self.b = b     }      func isidentical() -> bool {         return === b     } } 

you need <t: anyobject> ensure t class.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -