Skip to content

iOS example not working correctly, throws: mutation attempt of frozen kotlin.collections.HashMap #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
falcon4ever opened this issue Jun 29, 2021 · 2 comments
Assignees

Comments

@falcon4ever
Copy link

falcon4ever commented Jun 29, 2021

Hi,

I was following the tutorial Kotlin Multiplatform Hands-on: Networking and Data Storage from scratch using Android Studio Arctic Fox Beta 4 and KMM plugin v0.2.6.

The Android demo works great, the iOS demo seems to have a problem trying to retrieve the data from the shared KMM module.

I also noticed that the iOS template that's generated with KMM plugin v0.2.6 is different from the one in the tutorial and this repo. The plugin now generates a template with iOSApp.swift and ContentView.swift only (there is no AppDelegate.swift or SceneDelegate). In my fork I made some changes to make it run, unfortunately, it gives me the following error when launching: "mutation attempt of frozen kotlin.collections.HashMap@1cad628"

Screen Shot 2021-06-29 at 5 07 08 PM

Steps to replicate:

Any ideas how to fix the demo code?

I'm using:

  • Kotlin: 1.5.20
  • Coroutines: 1.5.0-native-mt
  • Serialization: 1.2.1
  • ktor: 1.6.0
  • sqldelight: 1.5.0

edit June 30th 2021
I also tried updated the existing final branch to see if it was some XCode proj issue (but it gives the same result):

@falcon4ever
Copy link
Author

Ok, figured it out and it's related to the serialization library:

If you add useAlternativeNames = false in SpaceXApi.kt the iOS app will work correctly:

class SpaceXApi {
    private val httpClient = HttpClient {
        install(JsonFeature) {
            val json = Json {
                ignoreUnknownKeys = true
                useAlternativeNames = false
            }
            serializer = KotlinxSerializer(json)
        }
    }

@KaterinaPetrova
Copy link
Collaborator

Hey @falcon4ever, thanks for reporting it. I've updated the sample (added a workaround). The final branch was forced-pushed (to keep the clean history, which represents the steps of the tutorial)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants