Is there any way of doing something like this On ...
# multiplatform
c
Is there any way of doing something like this On common.kt
Copy code
expect fun foo(font: UIFont)
I mean, having some platform specific parameter on the expect? Or do I have to resort to use
Any
? Thanks!
r
You could also expect/actual the parameter
c
Like this @russhwolf?
Copy code
expect fun foo(expect font: UIFont)
r
no, like
Copy code
expect fun foo(font: Font) 
expect class Font
c
And is there any way of then on the iOS side for example do something like
Copy code
actual class Font = UIFont
?
Because I want to use a class that already exists on the iOS/Android side
r
yeah that's exactly what you'd do
c
It gives me the following:
Expecting a top level declaration
on the AndroidMain
r
Are you not doing a top-level class?
c
I’m declarating it inside my androidMain/actual.kt
r
oh sorry. You want to do
actual typealias Font = ...
c
Why the typealias? Just curious
r
You're typaliasing
Font
to the platform-specific type
actual class
defines a new class
c
Oh.. and should I do on the
expect class Font
as well?
r
no that's still
expect class
c
Yeah, got it!
r
c
By the way, and somewhat unrelated. But is there a way of overloading
expected
methods and using an OptionalExpectation? Something like:
Copy code
@OptionalExpectation
expect fun foo(bar: String)

@OptionalExpectation
expect fun foo(foo: String)
And then on the platform specific only implementing the one we want? For example the first one being for Android and the second one for iOS
r
No,
@OptionalExpectation
only works for annotations
👍 1
Otherwise you might try to call that function from common and not know it's missing
c
Yeah, thats what I thought. Thanks a lot for your help!
👍 1