hi everyone. I have network call done in kmp and t...
# multiplatform
s
hi everyone. I have network call done in kmp and the response will be consumed on ios native app through OBJ-C header. One of the response model that I created is structured like this.
Copy code
@Serializable
data class ScoreInfo(
  @SerialName("tier_mapping")
  val tier: Tier? = null,
  @SerialName("score")
  val score: Int? = null,
  @SerialName("info")
  val info: Map<String, InterestInfo?>? = null,
)

@Serializable
data class InterestInfo(
  @SerialName("interest_rate")
  val InterestRate: InterestRate? = null,
)

@Serializable
data class InterestRate(
    ...
)
the
ScoreInfo
and
Tier
data class is defined in OBJC header but the
InterestInfo
data class is not. context: my app is a native iOS app created in swift. Then I have a project to add a VC created in CMP as a childViewController of a page in native swift. I created a function in
shared.kt
which return
ScoreInfo
data class because I want to save it into the ios app localdb. I face a hard time to save it into ios localDb because the property
info
is declared as
interestInfo:(NSDictionary<NSString *, *id*> *)interestInfo
in OBJC header.
id
in OBJC could be any object. I wish I can typecast it into
InterestInfo
but it is not declared on OBJC header somehow. need a clue here. 🙂
m
Nullable types don't play nice with the Objective-C interop. So if you could change
Map<String, InterestInfo?>
to
Map<String, InterestInfo>
I think that would help. Maybe a computed property that removes the nulls.
👀 1
s
Thanks for your idea. Yeah, I notice that too. I can’t remove the optional type because it is an existing API contract. Changing it means the BE need to adjust and do the versioning.