I know cocoa application has a main run loop, how to make a function been called every frame? I mean this function should be called every process of the main loop. Is that through the -(void) run of the + (NSRunLoop*) currentRunLoop;?
Asked
Active
Viewed 418 times
2 Answers
2
You can call getCFRunLoop to get the Core Foundation RunLoop. Then it's just a matter of adding an observer to the CFRunLoop. See the docs for this function:
CFRunLoopAddObserver()

par
- 17,361
- 4
- 65
- 80
-
2Note that this won't get the observer function called at fixed intervals, because a run loop does not fire at fixed intervals. There is no constant “frame rate”. A run loop executes something when something needs to be executed; until then, the run loop may sleep for any amount of time, from microseconds to years. On the one hand, this may be exactly what you need—if nothing is happening in your application, maybe you don't need to do anything about that. On the other hand, if you need something to fire at a fixed or maximum interval, you'd be better off with a timer or delayed perform. – Peter Hosey Jan 16 '11 at 10:43
0
I'm assuming you are targeting OSX since the tag is cocoa and not cocoa-touch so if you want to synchronize with every screen frame update you should check out CVDisplayLink
I know it's been quite some time. Anyway this might come useful for someone who stumbled upon here like me.

mixolydian
- 15
- 1
- 5