How to build an iOS Streaks App and Widget
Vložit
- čas přidán 22. 06. 2023
- In this video, you’ll learn how I built a streaks app with a complimentary iOS widget and how I kept the data in sync using App Groups. You’ll also learn about iOS widgets and how they work.
Sign up to our newsletter to download the Source code and project: www.getdrip.com/forms/4303814...
Links and references from the video:
- CWC+: learn.codewithchris.com/colle...
- Timeline Provider: developer.apple.com/documenta...
- AppIntents:developer.apple.com/documenta...
- Keeping a widget up to date: developer.apple.com/documenta...
- @KavSoft Circular Progress Ring: • SwiftUI 3.0 Apple Bed ...
Steps:
00:56 Start the Xcode project
01:21 Add the counter and button
03:26 Build the progress ring
08:53 Style the text and background
12:02 Add a widget extension
13:53 Walkthrough of the Widget code
25:33 Set up an App Group
29:49 Set up the DataService in the Widget
31:35 Build the Widget UI
38:07 Manually update the widget from the app
39:37 Add an app intent to the project
Thanks for this Chris! Got everything working except for the AppIntent at the end to increment the streak count when tapping on the widget. When I tap on the widget it just loads the full app. I’m gonna circle back though and confirm I didn’t miss anything
Me too. How to fix.😂
I solved it. like this
Button(intent: AppIntent()) { ... } // If has AppIntent(),tap on the widget not loads the full app.
my app group container is staying red in signing and capabilities
Thanks
Hi Chris, would it be possible to create a button to refresh the widget, but also at the same time, a timeline to keep the widget up-to-date? If I click the refresh button, would the timelines reseted?
I have a decent understanding of UIKit having taken Angela Yu's course 3 years ago. I've recently got that itch to get back into Swift and try to dive deeper into SwiftUI now that it's had time to mature. Do you think it's worth delving deep into SwiftUI to try and land that work from home job as a SwiftUI dev with some pretty basic UIKit understanding (Classes, structs, API's etc). Or would mastering UIKit and then move onto SwiftUI be what I should be focusing on? I'm just trying get that dev job in the next 3 months really diving into this and am worried I might kinda waste my time when I could be focusing on the future of SwiftUI. Any insight would be fantastic. Thank you Chris and keep up the great videos!
I'm not Chris, but I thought I'd share what I would do in your situation (I also started with Angela Yu's course and am now a full time iOS Engineer at Lyft!).
If your top priority is landing an iOS Developer job, I would start learning SwiftUI just because it's another skill on your resume (and will open many more doors than mastering UIKit would). Most of the iOS community agrees that SwiftUI will become a large part of the future of iOS development (if not already). Mastering UIKit now would certainly prove useful, but those skills will inevitably become less and less valuable as the technologies begin to shift (in this case, it is better to start to learn technologies on the uprise imo).
With that said, having UIKit skill/experience is very important since it is an imperative framework (where SwiftUI is declarative). If you don't understand what this distinction means, I implore you to look into it (it may even help you in an interview one day). Even if SwiftUI takes over, UIKit will pop up now and again, so make sure that you are still skilled with the UIKit fundamentals.
In our opinion, majority of companies (like 95% of em) still have their apps codebase written in UIKit, and a few (about 30%) are slowly transitioning into SwiftUI. The reason that there is a friction to adoption is that companies wanted to cover as much userbase as possible, and to do that they have to support older versions of iOS.
You're also correct that SwiftUI is the future, and that Apple is clearly pushing it on every WWDC, but each improvement they do to SwiftUI is only available to the iOS version coming out that year, and it isn't backwards compatible to older versions of iOS, which is why companies can't easily make the transition or simply adopt SwiftUI at 100% of their codebases.
So your goal of refreshing your UIKit knowedge is on track if you wanted to get employed as a developer. If you land a job, that may be the best time to learn SwiftUI unless the position specifically requires SwiftUI knowledge right off the job posting. - Pat
Hello Chris
I want to have multiple widgets under same target. Can you help me with the same?
in ios 17 containerBackground not working for me
It should be working. XCode generated containerBackground() call for you, so you must delete it first.
did you get it working?
noob question here, is the widget deployed along with the app in the appstore?
Hello @EmanNollase
Yes, when you deploy your app to the App Store, the widget comes along with it.
The widget system uses the same easy WidgetKit API across various environments such as the Home screen, Lock screen, StandBy mode on iPhone, Smart Stack on Apple Watch, and desktop on Mac, allowing your widget to be automatically adaptable to these different locations. So, when you publish your app to the App Store, the widget included in your app will be deployed along with it. The viewers of your widget will depend on the device they are using, and the context in which they choose to use it.
Resource: Bring widgets to new places [developer.apple.com/videos/play/wwdc2023/10027/]
--Joash
@@CodeWithChris thanks...i am planning to add widget to the app i am currently developing..thanks for the tutorial!
Wishing you the best of luck on your app, @EmanNollase!
--Joash
😠 *Promosm*
Nice job 👍
Thank you! Cheers! - Pat