I’m doing some multiplatform date work. Currently...
# multiplatform
s
I’m doing some multiplatform date work. Currently I have an expect class called
Date
. I have it aliased on the jvm as
Copy code
actual typealias Date = java.util.Date
I would like to define a method in the expect class called
before(date: Date): Boolean
. Currently I’m doing it like:
Copy code
expect fun Date.before(date: Date): Boolean
//jvm
actual fun Date.before(date: Date): Boolean {
    return this.before(date)
}
This gives me a shadowing warning. Is there a way to do something like
actual  fun Date.before(date: Date): Boolean = java.util.Date.before
?
r
Well you’re defining a function identical to another one so you’re guaranteed to have problems
r
Never tried something like that but you might actually be fine since the thing your shadowing is what you call from the extension function anyway. Will probably look funny when you're interacting with it from JVM code instead of Common though
s
The code works but I get a warning. I want to tell the compiler that this extension method is already handled by the type. I would define the method in the expect class but on iOS I’m type aliasing
Date
to
NSDate
and it doesn’t have a before method.
r
I think you should just suppress the warning if you can
My take on a KMP Date is
class Date(val time: Long)
🙂 actually
inline class
if they were serializable…
s
I’d prefer to use typealias since it makes it easer to pass along to platform methods that already work with those objects without doing any conversions.
r
Yes, that was my initial idea too. But caused to many issues on other platforms, and the autocompletion is bloated with all the native functions + the one I defined in common, often clashing like the issue you have now. I got rid of all of that in exchange of some calls to a
.native
extension to get the platform type
c
Are inline classes multiplatform ready? I always assumed they were JVM only
Okay if I understand now, you cannot use inline class on Swift or ObjC (because there is no way to represent an inline class in those languages). But, you can use it in common Kotlin code. There are discussions on GitHub about being able to access the "wrapped" value of an inline class from Swift, but I haven't tried it yet