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

Rishabh Harit

10/30/2019, 12:11 PM
Can someone tell me how can we add platform specific secondary constructors to a class?
s

Sam

10/30/2019, 12:27 PM
It isn’t possible at this time unless your class is an expect class. Unfortunately expect classes can only have declarations and no shared implementations. You could write top level functions that look similar to constructors. Another idea, if your class is complicated enough, mimic what Ktor does for initializing the HttpClient and have the constructor take a block which it passes a configuration object that has methods called and properties set on it. Then the actual object reads those values to initialize itself. You end up with something that looks like a nice dsl.