File tree Expand file tree Collapse file tree 2 files changed +7
-0
lines changed
commonMain/kotlin/com/example/fruitties/viewmodel
iosMain/kotlin/com/example/fruitties/di/viewmodel Expand file tree Collapse file tree 2 files changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ class CartViewModel(
31
31
private val repository : DataRepository ,
32
32
) : ViewModel() {
33
33
init {
34
+ // Leaving the comments here to show when the ViewModel is created.
34
35
Logger .v { " CartViewModel created" }
35
36
}
36
37
Original file line number Diff line number Diff line change @@ -3,12 +3,18 @@ package com.example.fruitties.di.viewmodel
3
3
import androidx.lifecycle.ViewModel
4
4
import androidx.lifecycle.ViewModelProvider
5
5
import androidx.lifecycle.ViewModelStore
6
+ import androidx.lifecycle.ViewModelStoreOwner
6
7
import androidx.lifecycle.viewmodel.CreationExtras
7
8
import kotlinx.cinterop.BetaInteropApi
8
9
import kotlinx.cinterop.ObjCClass
9
10
import kotlinx.cinterop.getOriginalKotlinClass
10
11
import kotlin.reflect.KClass
11
12
13
+ /* *
14
+ * This function allows retrieving any ViewModel from Swift Code with generics.
15
+ * We only get [ObjCClass] type for the [modelClass], because the interop between Kotlin and Swift
16
+ * code doesn't preserve the generic class, but we can retrieve the original KClass in Kotlin.
17
+ */
12
18
@Suppress(" unused" ) // Android Studio is not aware of iOS usage.
13
19
@OptIn(BetaInteropApi ::class )
14
20
@Throws(IllegalStateException ::class )
You can’t perform that action at this time.
0 commit comments