Re: ViewModel for iOS: I am still confused what is...
# compose-ios
t
Re: ViewModel for iOS: I am still confused what is supported and what is not. I see the 1.6.10-beta01 release refer to using ViewModel with the following comment:
Copy code
For using ViewModels outside of NavHost you need to provide custom store owner via LocalViewModelStoreOwner
I want to use the ViewModel as a base for my own ViewModels to have access to viewModel(Coroutine)Scope. Is this possible with the current alpha04 version, and if so, any examples out there? Thank you!
i
The comment is about
LocalViewModelStoreOwner
that defines lifetime of your
ViewModel
s. Currently there is no default one outside of navigation
1
It's temporary - Compose Multiplatform will implement
LocalViewModelStoreOwner
👍 1
t
Well, I cannot even get that far: when I add
Copy code
implementation(libs.androidx.lifecycle.viewmodel)
to my commonMain, my iOS build fails with:
Copy code
Showing Recent Messages
No matching variant of org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3 was found. The consumer was configured to find a library for use during 'kotlin-api', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_simulator_arm64', attribute 'org.jetbrains.kotlin.platform.type' with value 'native' but:
i
libs.androidx.lifecycle.viewmodel
It's a reference to toml. What package and version are you trying to use?
t
sorry, this:
Copy code
androidx-lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "lifecycle" }
where
Copy code
lifecycle = "2.8.0-alpha04"
maybe i dont want the ktx version anymore, since i think it is pure kotlin anyway
i
https://developer.android.com/jetpack/androidx/releases/lifecycle#2.8.0-alpha02
• The
lifecycle-viewmodel-ktx
kotlin extensions have now been moved to the base lifecycle module. (Id787b, b/274800183)
• The
lifecycle-runtime-ktx
kotlin extensions have now been moved to the base lifecycle module. (Ic3686, b/274800183)
• The
lifecycle-livedata-core-ktx
kotlin extensions have now been moved to the base lifecycle module. (I54a3d, b/274800183)
1. *-ktx are not multiplatform 2. It's a Google's package: it will work on iOS, but if you need web too use JB's one:
org.jetbrains.androidx.lifecycle:lifecycle-*
. It will redirect to Google's one on supported platforms.
Please note that our versioning a bit different: as mentioned in changelog:
- Lifecycle libraries
androidx.lifecycle:lifecycle-*:2.8.0-alpha01
. Based on:
- [Lifecycle 2.8.0-alpha04](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.8.0-alpha04)
it's only 2.8.0-alpha01
t
Ugh, I did not even notice that org.jetbrains. Sooo many packages....
If my hair was not already gray, it would be worse..
Okay, all better now. Thank you so much!
❤️ 2