How can I make my Objective-C class conform to Swift's `Equatable` protocol? -


i have objective-c class (that happens button, not important), , @ part of (mixed language) project, have array of these buttons , i'd index of button using find() method. so:

func dosomethingwiththisbuttonindex(index:int) {     let buttons = [firstbutton, secondbutton, thirdbutton]     if index == find(buttons, firstbutton)     {         // we've selected first button     } } 

but i'm getting

type 'implicitlyunwrappedoptional' not conform protocol equatable

okay, lets go objective-c , have buttonthing implement <equatable>. doesn't recognize that.

so do? i'm building around it, forcing array nsarray , using indexofobject. ugly. , frustrating.

first, in swift write custom == operator function class.

second, in swift, write class extension adds equatable protocol conformance.

perhaps, example:

func == (lhs: yourclass, rhs: yourclass) -> bool {     // whatever logic necessary determine whether equal     return lhs === rhs }  extension yourclass: equatable {} 

and class conforms equatable, swift specific. can not on objective-c end because can not write custom operators objective-c.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -