https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
n

Nick Halase

01/31/2020, 2:22 AM
Is there something I can do to make
Copy code
fun sectionForIndex(index: Int): Section?
not compile to
Int32
in my objective-c framework?
I may just not know enough Swift, but it's annoying not being able to pass a Swift
Int
to this function.
s

Sam

01/31/2020, 2:30 AM
Change it to:
Copy code
fun sectionForIndex(index: Long): Section?
n

Nick Halase

01/31/2020, 2:32 AM
Is this intentional design by Jetbrains?
s

Sam

01/31/2020, 2:32 AM
Kotlin Ints are 32-bit whereas Swift integers are 64-bit on 64-bit platforms.
n

Nick Halase

01/31/2020, 2:32 AM
doh, okay. thank you
s

Sam

01/31/2020, 2:34 AM
Beware of that if you plan on targeting older iOS devices/versions as it will cause some pain. For the most part 32-bit iOS stuff has been dead for long enough that it isn’t hard to justify not supporting it.
n

Nick Halase

01/31/2020, 2:34 AM
Good catch!
Are there any Kotlin/Multiplatform "gotcha" pages we could add this to?
s

Sam

01/31/2020, 2:36 AM
I’m not aware of any.
k

kpgalligan

01/31/2020, 2:37 AM
Would be a big page. I kid.
n

Nick Halase

01/31/2020, 2:38 AM
Gotcha #1: using experimental, unreleased frameworks
k

kpgalligan

01/31/2020, 2:38 AM
What, mutliplatform? Experimental, maybe, but not unreleased.
Also, I think technically the multiplatform is experimental, but native is beta, but I may be misremembering that.
n

Nick Halase

01/31/2020, 2:40 AM
unreleased was probably too strong of a joke, but that's interesting about native.
k

kpgalligan

01/31/2020, 2:44 AM
The platform is “stable” in the sense that the runtime is OK. There’s definitely a few surprises, though. All improving over time.
n

Nick Halase

01/31/2020, 2:57 AM
@Sam Long semi-works, but now it requires an
Int64
wrapper. Was this what you expected?
b

baxter

01/31/2020, 3:16 AM
There’s some info about primitive numbers interop between Kotlin <-> iOS (https://kotlinlang.org/docs/reference/native/objc_interop.html#nsnumber). Looks like you can pass in an
NSNumber
object instead.
s

Sam

01/31/2020, 3:16 AM
It isn’t quite the way I remember it working no.
k

kpgalligan

01/31/2020, 4:04 AM
If the type you’re expecting is an Int or Long, you can’t pass in NSNumber. That’s for a different situation (I assume. Too late/tired to try to make an example). I’m pretty sure you do need to explicitly cast to Int64. Not ideal, but you know. It works. I’ve been mostly passing objects in/out, so I’m a little rusty on how primitives work.
n

Nick Halase

01/31/2020, 4:47 PM
@kpgalligan thanks for the sanity check. If it's the way it is, that's fine, it does work after all, but it's good to hear that's apparently the common solution.
4 Views