Passing Data to Widget

I have an app coded with UIKit and want to add a simple Widget with Widgetkit. How can I pass the data to the Widget?
As you know the widget works with SwiftUI.

I only need to pass one variable. Thats it. The rest will be done with SwiftUI.

I tried it with UserDefaults but it didn't work.
This should answer.
https://stackoverflow.com/questions/50149072/transfer-data-from-project-to-widget-in-swift

Could you show how you tried to use UserDefaults ?

You should find more information in this tutorial.
https ://www.raywenderlich .com/11303363-getting-started-with-widgets

Hope that helps.
You can use App Groups or any other mechanism you would use to share data between your app and an extension. See here for more information.
Can we access NSPersistentCloudKitContainer in the same way we do from the app, or will we need still need App Groups?

I don't think CloudKit containers work with App Groups.
Passing Data to Widget
 
 
Q