Skip to content

Commit 407f6f3

Browse files
committed
Let the IOSViewModelStoreOwner implement the StoreOwner interface
1 parent f8c384c commit 407f6f3

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Fruitties/iosApp/iosApp/IOSViewModelStoreOwner.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import shared
33

44
/// A ViewModelStoreOwner specifically for iOS.
55
/// This is used with from iOS with Kotlin Multiplatform (KMP).
6-
class IOSViewModelStoreOwner: ObservableObject {
6+
class IOSViewModelStoreOwner: ObservableObject, SwiftViewModelStoreOwner {
77

8-
private let viewModelStore = Lifecycle_viewmodelViewModelStore()
8+
var viewModelStore: Lifecycle_viewmodelViewModelStore =
9+
Lifecycle_viewmodelViewModelStore()
910

1011
/// This function allows retrieving the androidx ViewModel from the store.
1112
func viewModel<T: Lifecycle_viewmodelViewModel>(

Fruitties/shared/src/iosMain/kotlin/com/example/fruitties/di/viewmodel/ViewModelStoreUtil.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ fun ViewModelStore.getViewModel(
2424
val provider = ViewModelProvider.create(this, factory, extras ?: CreationExtras.Empty)
2525
return key?.let { provider[key, vmClass] } ?: provider[vmClass]
2626
}
27+
28+
/**
29+
* The ViewModelStoreOwner isn't used anywhere in the project, therefore it's not visible for Swift by default.
30+
*/
31+
@Suppress("unused")
32+
interface SwiftViewModelStoreOwner : ViewModelStoreOwner

0 commit comments

Comments
 (0)