0

I was trying to make a widget for the app, but struggling to get the right data to the widget.

  1. App is written in Swift 5.
  2. I need to get data with the progress of the user
  3. Depending on the user progress (if there is some progress show some content depending on progress if there is no progress show different view that would ask to start the program)

So the problem is with #2 getting the data from the app.

In most tutorials, I saw only SwiftUI and WidgetKit, but not UIKit + Widgets, so I really need help to get started.

The app is quite complex already, and don't want to add all files as targets to the .widget if possible.

Answers might help in future for everyone else I guess who will be working with Swift and Widgets.

Thanks in advance!

Jkrist
  • 748
  • 1
  • 6
  • 24
  • Does this answer your question? [Share data between main App and Widget in SwiftUI for iOS 14](https://stackoverflow.com/questions/63922032/share-data-between-main-app-and-widget-in-swiftui-for-ios-14) – pawello2222 Sep 27 '20 at 18:35
  • Hello @pawello2222. Thank you for the response. This one uses core data or user defaults, and my progress is being kept in firebase, but in the app, I have some methods that will decide about the users progress. Not sure if my comment helped. – Jkrist Sep 27 '20 at 18:42
  • Your question is about *Getting data from UIKit to WidgetKit in Swift*. So, if you have some data in Firebase and you fetch it in your app, then you can pass it to the Widget using UserDefaults/CoreData/etc. If you want to fetch data from Firebase directly in the Widget then why did you mention UIKit and omit Firebase? – pawello2222 Sep 27 '20 at 18:51
  • @pawello2222 I mean that I already have methods in-app that fetch all the data and decides which progress to show. My question was if I could still use those methods or do I have to redo the logic, fetching data from Firestore, or add some writers to local storage. Is there an easy way to do, or just redo all the logic in the widget kit? – Jkrist Sep 28 '20 at 06:37
  • 1
    After you add a Widget target in your app, you can add some already existing files to this target. There’s no need to duplicate code. – pawello2222 Sep 28 '20 at 07:25

0 Answers0