开发者

Is there a way to be calling a method constantly while the program is running in Objective-C?

开发者 https://www.devze.com 2023-03-18 04:29 出处:网络
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 possibl

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消