So, hello people, I’m trying to do something that ...
# multiplatform
c
So, hello people, I’m trying to do something that I expected to be rather simple and it’s not working. I have this object:
Copy code
data class LoginModel(
    @SerialName("username")
    val username: String?,
    @SerialName("password")
    val password: String?,
    @SerialName("userType")
    val userType: String = "PROFESSIONAL"
)
With the serialisers and all, when I try to access it in swift I find this: - (instancetype)initWithUsername:(NSString * _Nullable)username password:(NSString * _Nullable)password userType:(NSString *)userType And when I try to use it on my code it kinda foces me to put something on my variable with a pre defined value, like this: let login = common.LoginModel(username: emailTextfield.text, password: passwordTextField.text, userType: “PROFESSIONAL”) I can live with this but I would like to know if there is an immediate solution. PS: It works fine on android, as intended. How default values work on swift: https://docs.swift.org/swift-book/LanguageGuide/Functions.html
r
Default arguments aren’t translated from Kotlin to Swift because they can’t be represented in Objective-C. You can workaround in this case by manually defining a secondary constructor
Copy code
data class LoginModel(...) {
    constructor(username: String, password: String) : this(username, password, "PROFESSIONAL")
}
💪🏽 1
c
Thanks, I just read about Objective-C not supporting default values, unfortunately sounds like a “never gonna happen”
b
I think JB is working on direct swift interop, which would enable this. Also there's #serialization for such issues ;)
💪🏽 1
r
direct swift interop is in the long-term roadmap but it won’t be soon