How to use Timer and onReceive in SwiftUI | Continued Learning #24
Vložit
- čas přidán 26. 04. 2021
- Implementing a Timer in SwiftUI is as simple as one line of code! In this video we will add a Timer to our View and then explore several different methods to create custom animations and features. We will use the .onReceive function to listen to the Timer (also known as "subscribing"). This video will also serve as an introduction to Publishers and Subscribers, which we will expand on in the next video!
Next video: • Publishers and Subscri...
Last video: • Download JSON from API...
🤙 WELCOME BACK 🤙
WEBSITE: www.swiftful-thinking.com
DISCORD: / discord
GITHUB: github.com/SwiftfulThinking/
SAY THANKS: www.buymeacoffee.com/nicksarno
OTHER STUDENTS, JUST BECAUSE THIS VIDEO IS OLDER ITS STILL COMPLETELY VALID AND YOU SHOULD CHECK IT OUT! Gotta admit I put off watching this because of the date created, and how many SwiftUI lessons stay up when things have changed, causing so much frustration, BUT I SURE WISH I WOULD HAVE STARTED WITH THIS. Everyone just wants to show a basic timer, while we need to know how the user can push a button when time is up, etc... So THANK YOU. I have been struggling to find how to make a button disabled after one tap that gives a point. I know it has to be easy, but again so many teachers go over the same thing, so I am now going to really research your videos thinking I might find some outside the box answers I need. Thank you again!
what i really love about your tutorials is that you show reason why and how to implement. great work!
I appreciate that guyvenson. Thanks for watching!
Excellent video Nick, thanks. Examples are great and very easy to follow👌
Great video and easy to follow!
Thank you! Man. U really are a blessing
Thanks Thedren :)
my Xcode not showing color literal ..I am using Xcode 14.2
At 21:40 I thought that Nick's mac is going to fly away
Why does the timer only seem to work when running the simulator and not in preview like with yours? I've written it exactly as you. (I'm running Xocde 14 beta)
Bro you are really amazing!
one of my daughters is expecting, so thanks to you I have an app on my phone that tells me how many days/hours/minutes until the due date. Thanks
Great educational video, as always! Thank you. One question, for your last example, the automatic tab view page swipe one has a weird animation when the page number jumps back to 1. Any idea to avoid that? Thanks
Thanks so much for the quality and the pedagogy of your video I hope you will published some more video in view to build an app with all recommended skills in the iOS 's world.keep carry on;) all the best
Thanks for watching Rodolphe! I appreciate the comment.
Super helpful, as always. One question, how do you know so much about Match? 🙈
I feel for you, every time when the fans are spinning up ... I hope that you already got yourself an MBP with M1 chip, it is like magic. I'm not sure they even built a fan in it - if it has one, I may have to return it as I never heard them that far and they might be defective. :D
😂 death by fan
High Quality stuff
Thanks bhagyash!
Hi, perfect as always. Thank You.
If I can, I would like to ask You about some things I found. I have updated to XCode13(13.1) and I found, that "Color Literal" option is not available. Did You face it? Also live preview in Canvas does not work in this example - values does not change. In simulator works good.
Yea the color literal is apparently a bug in Xcode 13. Hopefully they will fix it soon. You can either use another color option, or if you type .... #colorLiteral( .... I believe it will still work. The canvas should be working still though, I'll have to check.
I am on Xcode 14 and still have the problem.
SOLUTION: Instantiate a Color Literal by typing: #colorLiteral() .Now create a Code Snippet of it so you can use tab completion anytime in the future.
Steps:
1, if you highlight and right click the box, click the button to create a code snippet,
2. give it a title "Color Literal" and a completion of "colorliteral" and click "done".
3. Now, in Xcode, anytime you type "colorliteral" and press tab, it will create a color literal.
Countdown to date worked on the Simulator but not the Canvas, I can't find out why the difference? Any idea?
Yes, same with me. There is some explanation for this I guess from Apple about certain limitations, but I don't get what can be done about it. Anyone?
Hey Nick @ around 14:11 you create a countdown to date....based on your code...how would you format a countdown to a specific day and time.... (ex: You have to create a video every Thursday by 7am and on Wed the timer counts down from 24 hours left)
good question
Great video, fans made my day 🤣
Sorryyyy 😂😅
Hi Nick Thank you for the great tutorial. I actually followed it and built a countdown timer, but I noticed that it runs only while in the foreground. The moment I switch to another app or go Home it stops running. Where to look for solution?
Hello, all code in iOS applications only executes while the app is in the foreground, unless you use background tasks or cloud functions.
Hello! So how exactly could I perform an action every day at a specific time. For example everyday at 12am I want to reset the users points. Thanks! Don’t stop working hard and you will achieve great things!
Performing an action every day at the same time is different that using a Timer. We use the Timer while objects are on the screen, it won't be active while the app is in the background. If you want to perform a task every day as 12am exactly, you would need some sort of cloud function. However, it's probably easier to just check the "current time" vs "12am" every time the user opens the app and perform the necessary actions at that time.
Hey Nick, what computer do you have?
I have a MacBook Pro! But I have a lot on it so I need to clean it up soon. Hopefully the fan wasn't too annoying -___-
How do we access color literal please??
What if we wanted a button rather than a word, that performs an action at end of the count down. I have been trying with help of this video but am missing something?
you can use onChange method and on a specific count you can perform any action.
“Color literal” won’t show up as a command in Xcode for me either
How do we access color literal now please??