I had to use a mix of things:
import WidgetKit
import SwiftUI
@main
struct widgetBundle: WidgetBundle {
@WidgetBundleBuilder
private var iOSAllWidgets: some Widget {
LockScreenWidget()
}
@available(iOSApplicationExtension 17.0, iOS 17.0, *)
@WidgetBundleBuilder
private var iOS17Widgets: some Widget {
LockScreenWidget()
LiveActivityWidget()
}
@available(iOSApplicationExtension 18.0, iOS 18.0, *)
@WidgetBundleBuilder
private var iOS18Widgets: some Widget {
LockScreenWidget()
LiveActivityWidget()
LauncherControlWidget()
}
var body: some Widget {
if #available(iOSApplicationExtension 18.0, *) {
return iOS18Widgets
} else {
return getWidgetsThatAreNOTControlWidgets()
}
}
private func getWidgetsThatAreNOTControlWidgets() -> some Widget {
if #available(iOSApplicationExtension 17.0, *) {
return iOS17Widgets
} else {
return iOSAllWidgets
}
}
}
If you add more than one if else block in the body it complains about control flow statements. You can't use WidgetBundleBuilder.buildBlock for control widgets. If you try to use the function alone, it complains that the function does not return the same type for all the return statements because somehow control widget doesn't conform to widget.
This will have to do until we get the fix in Xcode 16.1 beta 3.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: