4

Is it possible to create a dynamic list of widgets inside the body of WidgetBundle? For example:

@main
struct HomeWidgetBundle: WidgetBundle {
    
    @WidgetBundleBuilder
    var body: some Widget {
        
        List<Widget> {
            ForEach (0..<10) {index in
                 HomeWidget()
            }
        }
    }
}

This above example is just to clarify the question, the code is not compiling.

J.Doe
  • 326
  • 2
  • 14
  • The current example is too broad - please specify exactly what do you need. How is it dynamic? What and when should change? – pawello2222 Sep 20 '20 at 22:38
  • I need to let the user pick different widget types depending on the user database contents. – J.Doe Sep 21 '20 at 21:02
  • Then for now it looks like it's not possible - see https://stackoverflow.com/q/63797991/8697793 – pawello2222 Sep 24 '20 at 08:28
  • This is not currently possible. Instead you should offer all (theoretically) possible widgets and show some information in the widget to take action in the app to enable it. I think Apple shows how this could work in https://developer.apple.com/wwdc20/10194 (11:11) where you would dynamically provide options using an Intent and if there are "no user database contents" you could show a text guiding the user to login or select/create content. – fruitcoder Nov 06 '20 at 16:57

0 Answers0