Question

I am wondering if there is some way to run a function every minute in Cocoa. I, personally, will be using this for saving content as the user types it in case they quit - But I have seen this effect also used in Twitter clients. When the user keeps the window open, it will auto-update every x minutes without input from the user. It seems as if this is common, and the language allows it, I just can't seem to find documentation on it.

Thanks for any help!

Was it helpful?

Solution

I, personally, will be using this for saving content as the user types it in case they quit - But I have seen this effect also used in Twitter clients.

A better solution would be to be the text view's delegate, and respond to textDidChange: by creating the non-repeating timer (if you have not done so already or it has already fired) and setting its fire date to X seconds in the future. Then, the user loses no more than X seconds' worth of work, not up to one minute, and the timer is not firing when the user has not typed anything.

OTHER TIPS

I, personally, will be using this for saving content as the user types it in case they quit

Then you want autosaving, which takes care of that for you.

Check out the NSTimer docs. It does exactly what you want. You create an NSTimer that will repeat for as long as you want, and call a specific function with specified arguments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top