It seems that you need to create separate Widgets with their own view, entry, provider...
Here is a possible solution using WidgetBundle
:
- Create separate Widgets (make sure the
@main
annotation is not attached to any of them):
struct Widget1: Widget {
let kind: String = "Widget1"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Widget1Provider()) { entry in
Widget1Entry(entry: entry)
}
.configurationDisplayName("Widget1")
.description("This is an example widget v1.")
}
}
struct Widget2: Widget {
let kind: String = "Widget2"
var body: some WidgetConfiguration {
...
}
}
...
- For each Widget create its own View (possibly also separate Entries and Providers, depending on what you need):
struct Widget1EntryView: View {
var entry: Widget1Entry
var body: some View {
Text("Widget1")
}
}
struct Widget2EntryView: View {
var entry: Widget2Entry
var body: some View {
Text("Widget2")
}
}
...
- Use
WidgetBundle
to provide a bundle containing your Widgets:
@main
struct WidgetsBudle: WidgetBundle {
var body: some Widget {
Widget1()
Widget2()
// add more Widgets if you want
}
}
Note that @main
is attached to WidgetsBudle
and not to Widgets.