# multiplatform

Daniele B

03/20/2021, 12:34 PM
I am finally publishing a sample on Github for the D-KMP architecture. These are the characteristics: • it uses the latest declarative UI toolkits: JetpackCompose for Android and SwiftUI for iOS • it fully shares the ViewModel (and the DataLayer) via Kotlin MultiPlatform • it provides 2 types of functions to the UI layer: Event functions and StateProvider functions • it implements the MVI pattern and the unidirectional data flow • it uses Kotlin’s StateFlow for the multi-platform observable mechanism Any feedback is very welcome!
👍 10

Ian Arbuckle

03/20/2021, 2:20 PM
What makes you think sharing the View Model is a good idea? It is platform specific to Android where we need to implement the ViewModel. In a larger project, iOS may not want to implement MVVM pattern and opt for something like VIPER which is a common pattern in iOS. I'd like to keep it simple and only expose use cases and repositories in the shared code. Then you can decide what architecture pattern suits the iOS or Android platform.

Daniele B

03/20/2021, 2:49 PM
Hi @Ian Arbuckle, if you look at the code, you see that the shared KMPViewModel is actually wrapped into the Android ViewModel. Similarly on iOS, it’s wrapped into an “ObservableObject” Swift class. So, the shared ViewModel is actually fully compliant with the platform lifecycles. KMP is a very flexible technology, you can use in many different ways, for example just for sharing the data layer, or a single module of your app. The D-KMP Architecture is focusing on fully sharing the ViewModel (apart from the tiny wrapping layer I mentioned above), so that you can minimize the amount of code that is platform-specific. In this way we can develop apps where the only platform-specific code is the declarative UI layer. This means you can write apps that share 85% of the code across the different platforms. If you want to understand more, just clone the repo and run the app. So you can see it yourself. And please provide me your feedback too! We only grow by sharing!
👍 2