Skip to content

Commit e860db9

Browse files
committed
Add comments
1 parent 407f6f3 commit e860db9

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Fruitties/shared/src/commonMain/kotlin/com/example/fruitties/viewmodel/CartViewModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class CartViewModel(
3131
private val repository: DataRepository,
3232
) : ViewModel() {
3333
init {
34+
// Leaving the comments here to show when the ViewModel is created.
3435
Logger.v { "CartViewModel created" }
3536
}
3637

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
@@ -3,12 +3,18 @@ package com.example.fruitties.di.viewmodel
33
import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.ViewModelProvider
55
import androidx.lifecycle.ViewModelStore
6+
import androidx.lifecycle.ViewModelStoreOwner
67
import androidx.lifecycle.viewmodel.CreationExtras
78
import kotlinx.cinterop.BetaInteropApi
89
import kotlinx.cinterop.ObjCClass
910
import kotlinx.cinterop.getOriginalKotlinClass
1011
import kotlin.reflect.KClass
1112

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+
*/
1218
@Suppress("unused") // Android Studio is not aware of iOS usage.
1319
@OptIn(BetaInteropApi::class)
1420
@Throws(IllegalStateException::class)

0 commit comments

Comments
 (0)