Use for WidgetKit introduced in iOS 14 and macOS Catalyst 14
Questions tagged [widgetkit]
520 questions
25
votes
2 answers
Share data between main App and Widget in SwiftUI for iOS 14
@main
struct ClockWidgetExt: Widget {
private let kind: String = "ClockWidgetExt"
public var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider(), placeholder: PlaceholderView()) { entry in
…

codingManMAx
- 279
- 1
- 3
- 4
24
votes
3 answers
How to reset intent extension configurations in WidgetKit
I have an application where a user can login. If a user is logged in, then I display a placeholder for my widget and it's configurable through an intent extension.
The configuration has two options:
the first option depends on the username of the…

K.A.Q
- 469
- 4
- 13
24
votes
2 answers
iOS 14 Widgets: How to create different layouts for every widget size family?
I want to create different layouts for each widget size (i.e. small, medium, large). How can I branch my code according to widget's size?

Feridun Erbaş
- 573
- 1
- 6
- 19
24
votes
2 answers
iOS WidgetKit: remote images fails to load
I'm observing a bizarre thing: in the new widgets far too often remote images are not being displayed even though the image has been successfully loaded and placed in cache.
For image downloading I've tried:
SDWebImageSwiftUI
Kingfisher
SwURL
All…

Konstantin Loginov
- 15,802
- 5
- 58
- 95
23
votes
2 answers
Xcode 12 iOS 14 Widget without SwiftUI
Is it possible to create Xcode widget in Xcode 12 but without the use of SwiftUI and instead use XIB files to construct the Widget UI?

Vlad
- 5,727
- 3
- 38
- 59
21
votes
1 answer
How to change the padding above and below a SwiftUI Divider?
Right now, I have a VStack containing a Text, a HStack which contains a few more Texts, and a Divider between them. The problem is that the padding to the top and bottom of the Divider is too much on some smaller devices, making the result look…

jaltair9
- 331
- 2
- 5
20
votes
3 answers
Perform a deeplink from SwiftUI widget on tap
I have a simple widget (medium-sized) with two texts, and what I want is to be able to perform a deep link to lead the user to a specific section of my app, but I can't seem to find a way to do so.
The view I have written (which is very…

Another Dude
- 1,204
- 4
- 15
- 33
19
votes
1 answer
How to refresh Widget data?
My Code fetches two JSON variables and should show them on my Widget.
The Widget stays blank. Without widget it shows me everything correct in my application.
What am I doing wrong? The API in the code is only for testing so you can also check…

submariner
- 308
- 1
- 5
- 23
19
votes
2 answers
iOS 14 Widgets: Widget not rendering when list is used
I'm experimenting with iOS 14 widgets and have a weird issue. My widget is not loading when I'm using a List in the widget view. If I'm using HStack, VStack etc. all works ok.
Here is some simple code for the sake of example:
struct WidgetView: View…

chnski
- 557
- 1
- 4
- 20
19
votes
3 answers
Why do some views appear as a red no entry sign in widgets?
I've created a project in xcode 12 and added a Widget Extension target. The target is created and I'm left with a simple widget that shows the time. The preview of the widget works as expected and the widget is shown as expected in the simulator. …

Paul
- 1,897
- 1
- 14
- 28
19
votes
5 answers
Xcode 12 / iOS14 Widget "@main and must provide a main static function" error
Using Xcode 12 trying to create Widget app extension to my project.
Upon creating new Widget target I am getting the following error:
'Widget' is annotated with @main and must provide a main static function of type () -> Void or () throws -> Void.

Vlad
- 5,727
- 3
- 38
- 59
18
votes
2 answers
Fetch data from CoreData for iOS 14 widget
I want to display data fetched from Core Data in a widget. But @FetchRequest doesn’t work on widgets.
As I understand, we have to create an app group and make a shared persistent container.
What I want to know is how to read (fetch) data on widgets…

umayanga
- 2,254
- 3
- 15
- 26
18
votes
3 answers
Detect app launch from WidgetKit widget extension
Tapping a WidgetKit widget automatically launches its parent application. How can I detect if my application was launched from its WidgetKit widget extension?
I'm unable to find any documentation on capturing this in the applications AppDelegate…

Daniel Storm
- 18,301
- 9
- 84
- 152
18
votes
3 answers
How to reload timeline of iOS 14 widget from notification response?
I'm making a home screen widget for iOS 14 using the new WidgetKit and I want my widget timeline to refresh when the user responds to a notification.
This is what my code looks like currently:
func userNotificationCenter(_ center:…

Sarvesh
- 401
- 1
- 3
- 8
16
votes
1 answer
WidgetKit: .timer Text style expands it to fill the width, instead of taking space to fit the contained string
.timer Text style expands it to fill the width, instead of taking space to fit the contained string. Is there a way to change this behavior?
Text(entry.timeFinished, style:…

Alexey Primechaev
- 907
- 1
- 6
- 13