Has anyone managed to make SwiftUI Previews work o...
# multiplatform
m
Has anyone managed to make SwiftUI Previews work on XCode 16 when instantiating a Kotlin data class coming from KMP? We reuse ViewModels that expose a state object and have some SwiftUI views using that, however, previews are broken. We upgraded to Kotlin 2.0.21 already but it made no difference.
f
do you use static or dynamic shared lib?
m
Static
f
Try to use dynamic, it has a real impact for SwiftUI, but as I’m remembering it’s the static one, who is more stable... Using SwiftUI preview with KMP, it’s kind of unstable, especially with the latest Xcode version (who had some rework).
Your preview is using only DataClass?
m
I use static because I read it was the recommended approach to share the library
The interesting part is that XCode 15.4 works just fine
Yes, only trying to instantiate a data class and pass it to a view
ViewModel injection is part of a higher-up view, so that is not part of the preview
f
I’m going to dig a little bit
the dynamic shared lib seem to be working on preview
The type of library for iOS is important especially when using crash analytics.
GO dynamic lib if you can!
m
What are the implications of migrating it? To be honest, I'm not entirely sure of their differences. I'm also sharing resources (images, strings) through the XCFramework using Moko resources, that was painful to configure initially.
f
There a big difference of the final size of your binary app, loading time and build time. For the ressources, nothing change, it’s not related
m
Worse size and loading or better? 😆
f
static lib -> the binary content of your shared lib is merged inside your iOS binary app, the performance depends of the size. dynamic lib -> the binary content of your shared lib is loaded when the app is started, as an external file. Normally, the task embedAndSignAppleFrameworkForXcode your using do the job. there are nothing to updated except the
isStatic = false
of your shared gradle.
👍 1
Benchmark the difference, that’s all I can say 😄
m
Thanks @François! I appreciate the time and info 🙏
🍻 1
f
I’m here to help 😄 and still around the slack.
177 Views