Anybody else tired of all the Int <-> Int32 ...
# kotlin-native
t
Anybody else tired of all the Int <-> Int32 casting in swift with MP library? Anybody find a clean way around this?
s
eventually you could make a compiler plugin of some sort to ease the pain. Could you be more specific though as the what situation you are talking about though?
t
Whenever you define a variable with type Int on the Kotlin side, it gets defined as an int32_t in the Objective-C header. And then when using this to assign to any Int on the Swift side, you must explicitly cast to or from an Int32 (what int32_t is apparently equivalent to). So when pulling in any Kotlin you must do Int(x) and when calling any Kotlin code you must cast to Int32(x). So the more code we port to Kotlin the more casts we need.
s
Swift Ints can be 32 or 64 bit depending on what cpu the code is being compiled for. Kotlin doesn’t do that so there is a mismatch in semantics.
t
I understand that. Though you might think that if Kotlin Native is compiling for x64 or arm64, it ought to generate code such that a Kotlin Int -> int64_t, not int32_t. Perhaps there is a compiler switch we can turn on to make this happen? Also, since it seems everything is predominantly 64-bit now, I would expect the default to be int64_t, not int32_t.
s
Would just using Longs in your kotlin code work?
t
Perhaps. I am going to try that later today. Then see how the Android side reacts. 😕