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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.