Can anyone explain to me why it doesn't exit the while loop when there is no NSLog?
Your code (invisibly) uses the main thread's run loop to process connection and timer callbacks. Those callbacks control the connection object's state and, as a result, the loop condition.
When removing the NSLog
call the status cannot change as the main thread is blocked and the runloop cannot process its sources.
When inserting the call again, NSLog's implementation polls the runloop (maybe to communicate with the asl server). Within the call to NSLog
the run loop can dispatch delayed actions, timers or connection callbacks, as dbConnectionDidConnected:
. In this method the loop condition is becomes false and the loop exits as soon as the call to NSLog
returns.