Skip to content

Commit 77f04fc

Browse files
committed
Export ViewModel dependency to remove Lifecycle prefixes in Swift
1 parent 4dafc6e commit 77f04fc

File tree

3 files changed

+14
-29
lines changed

3 files changed

+14
-29
lines changed

Fruitties/iosApp/iosApp/IOSViewModelStoreOwner.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ import shared
33

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

8-
var viewModelStore: Lifecycle_viewmodelViewModelStore =
9-
Lifecycle_viewmodelViewModelStore()
8+
var viewModelStore = ViewModelStore()
109

1110
/// This function allows retrieving the androidx ViewModel from the store.
12-
func viewModel<T: Lifecycle_viewmodelViewModel>(
11+
func viewModel<T: ViewModel>(
1312
key: String? = nil,
14-
factory: Lifecycle_viewmodelViewModelProviderFactory,
15-
extras: Lifecycle_viewmodelCreationExtras? = nil
13+
factory: ViewModelProviderFactory,
14+
extras: CreationExtras? = nil
1615
) -> T {
1716
do {
1817
return try viewModelStore.getViewModel(

Fruitties/shared/build.gradle.kts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,17 @@ kotlin {
5050
// A step-by-step guide on how to include this library in an XCode
5151
// project can be found here:
5252
// https://developer.android.com/kotlin/multiplatform/migrate
53-
val xcfName = "shared"
5453

55-
iosX64 {
56-
binaries.framework {
57-
baseName = xcfName
54+
listOf(
55+
iosX64(),
56+
iosArm64(),
57+
iosSimulatorArm64()
58+
).forEach {
59+
it.binaries.framework {
60+
export(libs.androidx.lifecycle.viewmodel)
61+
baseName = "shared"
5862
}
5963
}
60-
61-
iosArm64 {
62-
binaries.framework {
63-
baseName = xcfName
64-
}
65-
}
66-
67-
iosSimulatorArm64 {
68-
binaries.framework {
69-
baseName = xcfName
70-
}
71-
}
72-
7364
// Source set declarations.
7465
// Declaring a target automatically creates a source set with the same name. By default, the
7566
// Kotlin Gradle Plugin creates additional source sets that depend on each other, since it is
@@ -90,7 +81,7 @@ kotlin {
9081
implementation(libs.ktor.client.content.negotiation)
9182
implementation(libs.ktor.serialization.kotlinx.json)
9283
implementation(libs.skie.annotations)
93-
implementation(libs.androidx.lifecycle.viewmodel)
84+
api(libs.androidx.lifecycle.viewmodel)
9485
implementation(libs.androidx.paging.common)
9586
implementation(libs.androidx.room.runtime)
9687
implementation(libs.sqlite.bundled)

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,3 @@ fun ViewModelStore.getViewModel(
3131
return key?.let { provider[key, vmClass] } ?: provider[vmClass]
3232
}
3333

34-
/**
35-
* The ViewModelStoreOwner isn't used anywhere in the project, therefore it's not visible for Swift by default.
36-
*/
37-
@Suppress("unused")
38-
interface SwiftViewModelStoreOwner : ViewModelStoreOwner

0 commit comments

Comments
 (0)