I had this problem before and my answer to your question based off of that would be to create a custom ViewModifier and use @ViewBuilder so you can handle the compilation error message.
Something like this should work:
struct DeviceAdaptedListStyle: ViewModifier {
var isPhone: Bool { ... }
@ViewBuilder func body(content: Content) -> some View {
if isPhone {
content.listStyle(.plain)
} else {
content.listStyle(.sidebar)
}
}
}
extension List {
func deviceAdaptedListStyle() -> some View {
modifier(DeviceAdaptedListStyle())
}
}
At the moment, there might be a better solution with Swift 5.5, but I haven't checked.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: