Alex Mortimer
01/27/2025, 2:26 PMexpect abstract class ViewModel()
with one open function onCleared()
. The ViewModel instances are accessed through Koin with this function: fun getBreedViewModel() = getKoin().get<BreedViewModel>()
, which is called from SwiftUI like so: let viewModel = KotlinDependencies.shared.getBreedViewModel()
.
I’ve also cloned the FantasyPremierLeague app, which uses the actual androidx.lifecycle.ViewModel
as a base class for its ViewModel classes in the shared module, and then creates instances of ViewModels in Swift code with an Owner class: class SharedViewModelStoreOwner<VM : ViewModel> : ObservableObject, ViewModelStoreOwner
.
As a caveat just to make things more complicated, I was planning on using Storyboards in my iOS app, since I haven’t worked with SwiftUI yet (primarily an Android dev).
Any advice on which approach to take here? I’ve tried to emulate the Fantasy Premier League app, since using the actual androidx ViewModel class is ideal, but haven’t gotten it to work. Asking for a friend 🙏François
01/27/2025, 2:47 PMFrançois
01/27/2025, 2:48 PMFrançois
01/27/2025, 2:57 PMAlex Mortimer
01/27/2025, 3:11 PMJason
01/27/2025, 11:31 PMAlex Mortimer
01/27/2025, 11:32 PMJason
01/27/2025, 11:34 PMAlex Mortimer
01/27/2025, 11:35 PMJason
01/27/2025, 11:45 PM