Skip to content
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

Issue with KMP and SwiftUI Screen Not Updating #23

Open
ch8908 opened this issue Oct 14, 2024 · 0 comments
Open

Issue with KMP and SwiftUI Screen Not Updating #23

ch8908 opened this issue Oct 14, 2024 · 0 comments

Comments

@ch8908
Copy link

ch8908 commented Oct 14, 2024

Hi, I'm just trying out KMP and would like to know why this won't work on SwiftUI.

I tried to modify the sample code with an old-school ViewModel style:

    private val _objects = MutableStateFlow(emptyList<MuseumObject>())

    @NativeCoroutinesState
    val objects: StateFlow<List<MuseumObject>> = _objects

    fun fetchAll() {
        viewModelScope.launch {
            val data = museumRepository.museumApi.getData()
            _objects.value = data
        }
    }

When calling fetchAll(), the code above works on Android, and the screen updates as expected. However, the screen doesn't update on SwiftUI.

I would really appreciate any guidance or suggestions you could provide. Thank you!

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

1 participant