I’m seeing an issue in Kotlin/Native where === is ...
# kotlin-native
m
I’m seeing an issue in Kotlin/Native where === is returning false for two variables that both point to same ObjC object (== works fine). Is this a known issue that === doesn’t compare pointers as expected when comparing ObjC objects? Or is my understanding of === equality missing something?
r
To hazard a guess, is the ObjC object wrapped in a Kotlin object, even internally? Because then
===
would be comparing the two Kotlin boxes by reference, and they wouldn't be equal
m
ahh, that could be it. Not ideal functionality but would make sense.
l
Do you have some minimal code that reproduces this?
m
@Landry Norris Sorry for delay. Here’s a quick example distilled to its simplest form that is failing for me.
Copy code
fun compare(item : Any, withItem : Any) : Boolean {
  return item === withItem
}
And then from ObjC I can call it like this
Copy code
BOOL equality = [[Utils shared] compareItem:view withItem:view];
And it will return false - where
view
is a UIView
l
I would imagine the Kotlin compiler wraps the Obj-C objects in a KObjHeader under the hood, and === is comparing that. If view were passed straight to Kotlin, I'd think === would work
m
that seems to be the case. Definitely something to be aware of that could catch you off-guard. Seems like something the Kotlin compiler should account for when compiling for objc targets.
l
Are you able to use == for this?
m
ya == works for me. I can’t think of an edge case where it wouldn’t, but === just seemed more precise for what I am trying to do
l
Yeah. It may just be something to note in some documentation. It makes sense that they wouldn’t add an exception to === for this case.