Use for WidgetKit introduced in iOS 14 and macOS Catalyst 14
Questions tagged [widgetkit]
520 questions
7
votes
1 answer
SwiftUI Widget DateStyle Custom Format
Just wondering if there is a way to apply a custom format for the DateStyle comp within SwiftUI's Text UI. For Example just the minutes or seconds like you would when using a DateFormatter. I want to display the dynamic dates for a Widget but it…

Russ
- 71
- 2
7
votes
0 answers
Widget getTimeline method called multiple times for customized intents
In my iOS 14 widget with a single custom intent, when the user selects one intent, then changes to another, my getTimeline method is called multiple times for each intent on each refresh - including previously-selected ones.
I would expect…

Daven
- 549
- 4
- 11
6
votes
2 answers
Full size AccessoryWidgetBackground() in accessoryRectangular family
I'd like to add a full size AccessoryWidgetBackground() to an accessoryRectangular widget family.
I made a brand new project and added a brand new widget. Then I changed the view to:
struct Some_WidgetEntryView : View {
var entry:…

lewis
- 2,936
- 2
- 37
- 72
6
votes
0 answers
Widget with relative date text not updating when device is locked
I have a widget with a SwiftUI Text timer date. It countdowns as expected. However, when the device is locked, the timer is frozen.
To reproduce it, add the SwiftUI Text(_:style:) view to a widget and place the widget on the "Today View". The…

TruMan1
- 33,665
- 59
- 184
- 335
6
votes
1 answer
SwiftUI Widget: 'main' attribute can only apply to one type in a module
I've created a Widget and I'm adding @main on top of the declaration.
However, when I switch to the Widget extension target and run it, I get the error 'main' attribute can only apply to one type in a module because I also have a @main in my main…

noloman
- 11,411
- 20
- 82
- 129
6
votes
0 answers
How to write UI tests for iOS Widget/WidgetKit?
So I am familiar with testing SwiftUI views, but how do I test the views used for the widget when they don't exist within the app after the app launches(As they are only being used within the widget)?
Additionally, what is the proper way to widget…

AK-Vitae
- 61
- 2
6
votes
1 answer
How to debug SwiftUI Widget memory issue?
I'm creating a widget in swiftui, with a prefilled mock json, stored locally.
Mock JSON has following data:
{
"id":"111",
"title":"some dummy title",
"date":"1609865285",
"thumbnail":"mock4"
}
and mock4 image is stored in the Assets…

Teja Nandamuri
- 11,045
- 6
- 57
- 109
6
votes
2 answers
iOS Add Button to Widget Extension
I am currently designing a widget for my app and basically, the widget should consist of three buttons. So far, I didn't find any tutorial on how to add buttons to an iOS Widget Extension. I see that e.g. Google Maps uses buttons in their…

ulrike_hansel
- 115
- 1
- 6
6
votes
0 answers
iOS Widget is crashing when cornerRadius or clipShape is applied in SwiftUI
My iOS Widget is crashing as soon I add the cornerRadius modifier to a view in my SwiftUI layout or a clipShape to clip a view.
Did anybody experience the same behaviour and found a solution?
I tried it with Xcode 12.1 and iOS 14.1 Simulator and…

fruechtemuesli
- 2,809
- 3
- 17
- 15
6
votes
2 answers
SwiftUI WidgetKit: How to anchor views to the top
I am attempting to layout a tableView using SwiftUI and WidgetKit and would like to achieve a similar result of that as the Apple's Notes widget.
My current implementation succeeds in laying out the view in the .systemLarge widget, but not in the…

Koh
- 2,687
- 1
- 22
- 62
6
votes
1 answer
How to display Current Time (Realtime) in iOS 14 Home Widget
I am developing an application for ios 14 Home Widget and I am facing a problem while showing the current time (digital clock) that the widget not getting updated every sec. As we all know, Apple does not allow to trigger timeline every second is…

user3634291
- 69
- 3
- 10
6
votes
0 answers
What is the reasonable way to display data from Core Data in iOS 14 widget?
I have an app that uses Core Data + CloudKit stack. (Core Data syncs between devices.). Now I want to display data from Core Data in iOS 14 widget (view in WidgetKit target).
My goal is to have data in widget also be actual data from Core Data: i.e.…

Igor R.
- 399
- 4
- 23
6
votes
2 answers
How to query WidgetKit if my widgets are being used?
I would like to check if the user added my widgets to the Home Screen, is there an API for this? I could not find one. WidgetCenter.getCurrentConfigurations returns all available widgets served by the app, not the used ones.
The reasons I look for…

mehmet6parmak
- 4,777
- 16
- 50
- 71
6
votes
2 answers
Communication between iOS app & Widgets for iOS 14
I'm currently creating my first widgets for my applications.
The data is obtained via an API call. I would like to know if it is possible to make this request from the application and then send the result of this request to the widget ? (a bit like…

jackson89
- 163
- 2
- 7
5
votes
2 answers
Widget on iOS 17 Beta device - Adopt containerBackground API
I'm working on an app + widget with Xcode 15 Beta. The widget works as expected on iOS 17 Beta simulators, but when running on my device with iOS 17 beta, it displays "Please adopt containerBackground API" instead of the desired content.
I searched…

CodeBrew
- 6,457
- 2
- 43
- 48