Kotlin / Kotlin/KMP-App-Template-Native

Issue with KMP and SwiftUI Screen Not Updating

Open
#23 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
284
Forks
44
Avg merge
14d 19h
Merged PRs (30d)
2

Description

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())

@NativeCoroutinesState
val objects: StateFlow> = _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!

Contributor guide

No contributing guide indexed for this repository

Research direction

No file or test is named. Start by locating the sample's SwiftUI observation of objects and the fetchAll entry point, then trace how the StateFlow is exposed across Kotlin and Swift. Done means data loaded by fetchAll is reflected on the SwiftUI screen, with a regression test if the existing project provides one.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, swift
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.