Member-only story

Widgets using SwiftData: iOS

4 min readSep 22, 2023

In this article, we will see how can we add widgets to our existing applications. For SwiftData, Please refer given article:

We will begin with adding new targets for our widgets.

Ensure both of these flags are unchecked.

Activate the widget and we are ready to roll.

We will get a dummy widget with lots of boilerplate code which is a good starting point for us. Let’s see how it works and what it is made up of.

Widgets Decoded

Widgets are added as a different target, which means it coexist with the main app but still is independent. It can make it’s own API calls, access locations etc.

The entry point of the widget is:

@main
struct TestWidgetsBundle: WidgetBundle {
var body: some Widget {
TestWidgets()
}
}

--

--

No responses yet