Closed qupig closed 1 year ago
Thanks @qupig! 😄
Sure, that's a valid concern in some cases. In that situation, you can also wrap the properties in #if
:
#if os(iOS)
private var body_iOS: some View {
// the body for iOS only
}
#endif
#if os(macOS)
private var body_macOS: some View {
// the body for macOS only
}
#endif
It's also worth pointing out that the compiler may (very likely) strip dead symbols also.
So for example, body_macOS
(without the #if
) might be removed by the compiler when building for iOS.
Thanks so much for leaving feedback about this blog post! After 2 weeks of inactivity these issues are automatically closed, but feel free to continue the discussion!
Comments, Questions, Feedback: https://www.jessesquires.com/blog/2023/03/23/improve-multiplatform-swiftui-code/
This approach really makes the code look neat.
But at the same time, we may lose the advantage that
#if os()
brings to us, that is, the compilation process omits code that is not related to the specific platform.In your example,
#if os()
is used to change theself
pointer, and all configuration code will be flooded to each platform.