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

dambakk

02/27/2020, 10:06 AM
This might be a very basic question, and I know there is an
expect/actual
answer to this question, but I cant seem to figure it out. We are using
Klock
to handle dates in our mpp project. How can we expose this type as a
NSDate
for the ios platform?
🇳🇴 2
a

Artyom Degtyarev [JB]

03/03/2020, 7:43 AM
Hello! These classes are not equivalent, so the only option will be to provide a function that takes a
Klock
instance as an input and has an
NSDate
return type. As the function has to have access to the
platform.Foundation.NSDate
, it should be written in the native source set of an Apple target.
d

dambakk

03/04/2020, 8:56 AM
But what should be the return type of the
expect
function that calls the platform defined functions?
a

Artyom Degtyarev [JB]

03/04/2020, 9:37 AM
I meant something like adding extension function
Klock.toNSDate()
to the native source set, not expect-actual machinery. I’m not sure that it would work, got to think some more on this problem
d

dambakk

03/04/2020, 12:32 PM
Ah, good idea! Unsure how this would be translated into obj-c tho, does it support extension functions?
Please come back to me if you want me to try out anything!
2 Views