Hi my fellow programmers, I'm new here and needing some help on updating UIView background with timers. Is it possible to have timers set within a specific hour range? I'm wanting to be able to have it where the background will change colors depending on what time of day it is. Also, could I have it to where it will update even if an user is not using the app? I want my app to be able to have really good UI and user experience without having to stay on the app. I have been researching timers, however they are using seconds, that's why I'm curios into if I can use hours instead. Thank you in advance!
I think you have two different tasks:
viewWillAppear
or in willMoveToWindow
with NSDate).To solve second task you can use timers. Just use timer to check time, for that you can schedule timer to nearest time where you should change the style:
let timer = Timer(fire: Date(timeIntervalSinceNow: 1000.0), interval: 60.0 * 60.0, repeats:true) { (sender) in
//check current time and update view's background;
//or send notification about time
}
RunLoop.current.add(timer, forMode: .common)
To make your code better, create some class that will incapsulate timer creation and posting notification about time changing.
UPD
I think you should start from the begin. First, read about UIViewController, UIView, NotificationCenter, Timer. Also you should read about a event-driven architecture. After that you will look at your application and will decide where you can add the colorUpdate func.
If you need complete solution without knowledge for your application you can find someone who can create it for you (On Freelance or Upwork or on in some other place where you can find outsourcers).
P.S.
Adding the colorUpdate func into NotificationCenter is a bad idea, you can add this method in to a handler of a Notification.