跳转至
Protocol

WidgetBundle

A container used to expose multiple widgets from a single widget extension.

Declaration

protocol WidgetBundle

Overview

To support multiple types of widgets, add the @main attribute to a structure that conforms to WidgetBundle. For example, a game might have one widget to display summary information about the game and a second widget to display detailed information about individual characters.

@main
struct GameWidgets: WidgetBundle {
    var body: some Widget {
        GameStatusWidget()
        CharacterDetailWidget()
    }
}
Learn more about how to create a widget via the Widget documentation.

Availability

iOS 14.0+

macOS 11.0+

Topics


Instance Property

body Declares the group of widgets that an app supports.


Associated Type

Body The type of widget that represents the content of the bundle.


Initializer

init() Creates a widget bundle using the bundle's body as its content.