Pergunta

How can I log every message sent in a single iteration of the Objective-C event loop?

I want to further my understanding of the Objective-C runtime and thought this would be a good start.

Foi útil?

Solução

These functions will cause all messages to be logged to a file in /tmp, based on the PID of the process. Good on simulator, but not on an iDevice.

// Start logging all messages
instrumentObjcMessageSends(YES);

// Stop logging all messages
instrumentObjcMessageSends(NO);

Outras dicas

The CFRunLoopObserver opaque type should do exactly what you want. It is

a general means to receive callbacks at different points within a running run loop.

Use the activity argument to its creation function to specify when you want your observer serviced. For your case, this will probably be either kCFRunLoopEntry or kCFRunLoopExit.

You can get the CFRunLoopRef from the current NSRunLoop, [[NSRunLoop currentRunLoop] getCFRunLoop], or by using CFRunLoopGetCurrent().

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top