Hi! Best practices question here!
Let's say I have an app that keeps track of online auctions, every auction is represented with an UIView that contains information about the auction. This UIView is re-used all over the place in the app; sometimes it's in a table cell, sometimes it's not.
Every auction should automatically countdown to when it finishes, so every minute a label in the UIVIew that keeps track of the time left is updated.
How would you solve this?
- a) Should each UIView contain a unique timer that fire every minute and updates the label?
- b) Should you subclass UILabel and make the timer self contained within the label itself?
- c) Should you have one global timer and let labels subscribe to it?
- d) Some other way!
I'm leaning towards implementing either a or b, but would love some feedback on the best way to implement this. I'm paralytically scared of creating a subscription to an event that's later not unsubscribed (preventing GC), or having a timer causing an update to a label that's null (crashing the app).