Consider the following code:
class MyController: NSObject, ObservableObject {
//...
@Published var myRapidlyChangingVar: MyEnum? = nil
//...
func calledAtHighFrequencyByExternalEvents(value: MyEnum) {
myRapidlyChangingVar = value
}
}
The value of myRapidlyChangingVar
needs to be set to nil
if no calls to calledAtHighFrequencyByExternalEvents()
have been made for 1 second.
What is the simplest and cleanest approach to adopt to achieve this?
Strikes me as the sort of thing which Reactive programming should make incredibly simple, but unsure where to start or what to search for.