Is there a way to be calling a method constantly while the program is running in Objective-C?
I want to call a method infinitely while the program is running to check 开发者_如何转开发for the change of state of something. Is it possible to do this when programming for the iPhone?
It is possible, just use a repeating NSTimer
.
However I would advise against the continuous polling to get the state - better to setup a callback/delegate/notification pattern to notify any observers of a state change.
You could also use Key Value Observing (KVO) to get notified when a value is updated.
Lots of food for thought and terms to research.
精彩评论