How to use Timer and onReceive in SwiftUI | Continued Learning #24

Sdílet
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

Komentáře • 42

  • @bugsyace
    @bugsyace Před rokem +4

    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!

  • @guyvensoncadet8424
    @guyvensoncadet8424 Před 3 lety +13

    what i really love about your tutorials is that you show reason why and how to implement. great work!

  • @trevormills
    @trevormills Před rokem

    Excellent video Nick, thanks. Examples are great and very easy to follow👌

  • @coffeeCatPeanutDust
    @coffeeCatPeanutDust Před 2 lety

    Great video and easy to follow!

  • @thedrenkemp124
    @thedrenkemp124 Před 3 lety +2

    Thank you! Man. U really are a blessing

  • @emdutt4012
    @emdutt4012 Před rokem +2

    my Xcode not showing color literal ..I am using Xcode 14.2

  • @dostonbek.rustamov
    @dostonbek.rustamov Před 2 lety +2

    At 21:40 I thought that Nick's mac is going to fly away

  • @KulturanCov
    @KulturanCov Před 2 lety +2

    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)

  • @ejazmuneeb
    @ejazmuneeb Před rokem

    Bro you are really amazing!

  • @dugrut1325
    @dugrut1325 Před 2 lety +1

    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

  • @maroonaggie
    @maroonaggie Před rokem

    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

  • @rodolphe8859
    @rodolphe8859 Před 2 lety +1

    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

  • @mystride
    @mystride Před 2 lety

    Super helpful, as always. One question, how do you know so much about Match? 🙈

  • @BenjaminEggerstedt
    @BenjaminEggerstedt Před 2 lety +1

    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

  • @bhagyashingale5663
    @bhagyashingale5663 Před 2 lety +1

    High Quality stuff

  • @Nunny25
    @Nunny25 Před 2 lety +4

    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.

    • @SwiftfulThinking
      @SwiftfulThinking  Před 2 lety +3

      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.

    • @jd_paul
      @jd_paul Před 11 měsíci

      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.

  • @dugrut1325
    @dugrut1325 Před 2 lety +1

    Countdown to date worked on the Simulator but not the Canvas, I can't find out why the difference? Any idea?

    • @KulturanCov
      @KulturanCov Před 2 lety

      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?

  • @30guarino
    @30guarino Před 2 lety

    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)

  • @pawixu
    @pawixu Před rokem

    Great video, fans made my day 🤣

  • @pifeeder9027
    @pifeeder9027 Před 2 lety

    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?

    • @SwiftfulThinking
      @SwiftfulThinking  Před 2 lety

      Hello, all code in iOS applications only executes while the app is in the foreground, unless you use background tasks or cloud functions.

  • @pawelpow
    @pawelpow Před 2 lety

    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!

    • @SwiftfulThinking
      @SwiftfulThinking  Před 2 lety

      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.

  • @user-ry6ix2mr8y
    @user-ry6ix2mr8y Před 3 lety +2

    Hey Nick, what computer do you have?

    • @SwiftfulThinking
      @SwiftfulThinking  Před 3 lety +2

      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 -___-

  • @NyxAndrew
    @NyxAndrew Před měsícem

    How do we access color literal please??

  • @bugsyace
    @bugsyace Před rokem

    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?

    • @itsayan1616
      @itsayan1616 Před rokem

      you can use onChange method and on a specific count you can perform any action.

  • @ryanlipe6557
    @ryanlipe6557 Před rokem +1

    “Color literal” won’t show up as a command in Xcode for me either

    • @NyxAndrew
      @NyxAndrew Před měsícem

      How do we access color literal now please??