in KMP, how do you normally do if you need to pass
Context
via constructor for example to the
androidMain
but you don’t need it in
iosMain
? Because you can’t do something like
Copy code
// commonMain expect fun createThemePreferences(): ThemePreferences
// androidMain actual fun createThemePreferences(context: Context): ThemePreferences { // Has no corresponding expected declaration
return ThemePreferencesImpl(context)
}
e
escodro
11/25/2024, 6:34 PM
What I did in my app was not
expect
the function directly but an interface. Then, I could inject
Context
into the actual class implementation and not need this information in the function itself.