Rak
06/17/2021, 9:55 PMclass Greeting {
private val httpClient = httpClient() {
install(Logging) {
level = LogLevel.HEADERS
logger = object : Logger {
override fun log(message: String) {
Napier.v(tag = "HTTP Client", message = message)
}
}
}
install(JsonFeature) {
val json = Json { ignoreUnknownKeys = true }
serializer = KotlinxSerializer(json)
}
}.also { initLogger() }
@Throws(Throwable::class)
suspend fun greeting(): String {
return "${getHello().random().string}, ${Platform().platform}! X"
}
private suspend fun getHello(): List<Hello> {
return httpClient.get("<https://gitcdn.link/cdn/KaterinaPetrova/greeting/7d47a42fc8d28820387ac7f4aaf36d69e434adc1/greetings.json>")
}
}
I knew I wanted to do some json manipulation so I made the Json instance an instance variable:
class Greeting {
private val json = Json { ignoreUnknownKeys = true }
private val httpClient = httpClient() {
install(Logging) {
level = LogLevel.HEADERS
logger = object : Logger {
override fun log(message: String) {
Napier.v(tag = "HTTP Client", message = message)
}
}
}
install(JsonFeature) {
serializer = KotlinxSerializer(json)
}
}.also { initLogger() }
@Throws(Throwable::class)
suspend fun greeting(): String {
return "${getHello().random().string}, ${Platform().platform}! X"
}
private suspend fun getHello(): List<Hello> {
return httpClient.get("<https://gitcdn.link/cdn/KaterinaPetrova/greeting/7d47a42fc8d28820387ac7f4aaf36d69e434adc1/greetings.json>")
}
}
and now iOS crashes with an error:
Function doesn't have or inherit @Throws annotation and thus exception isn't propagated from Kotlin to Objective-C/Swift as NSError.
It is considered unexpected and unhandled instead. Program will be terminated.
Uncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen com.jetbrains.kmmktor2.Greeting@3dbf5e8
Anyone know why?louiscad
06/17/2021, 10:47 PMAnders Oedlund
06/18/2021, 12:30 AM