Member-only story

How to Support Multiple Widgets When Using WidgetKit?

Lee Kah Seng
3 min readJan 3, 2023

--

How to Support Multiple Widgets When Using WidgetKit?

This article is originally published at swiftsenpai.com

Having multiple widgets with various functionalities is quite a common feature for apps nowadays. For example, a shopping app can have a widget that shows today’s promotion and another widget that shows the user’s order status.

Apple has given us 2 ways to enable our apps to support multiple widgets:

  1. Using a widget bundle
  2. Having multiple widget extensions

In this article, we will look into both of these methods individually, so let’s get started.

Note:

If you are unfamiliar with how to create a widget using WidgetKit, I highly encourage you to first read my article called “Getting Started With WidgetKit” before proceeding.sw

#1: Using a Widget Bundle?

Let’s say we have implemented a widget named MyWidget1.

@main
struct MyWidget1: Widget {

var body: some WidgetConfiguration {
// Widget configuration here...
// ...
// ...
}
}

Since MyWidget1 has been annotated with the @main attribute, the system will take that as the widget extension entry point, and show the widget’s snapshot in the widget…

--

--

Lee Kah Seng
Lee Kah Seng

Written by Lee Kah Seng

Support me by becoming a Medium member: https://leekahseng.medium.com/membership ⦿ 🇲🇾 Creator of https://swiftsenpai.com ⦿ iOS developer since 2011

Responses (1)