I was trying to understand multithreaded programming in iOS.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
, ^{
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (connection == nil) {
NSLog(@"Request failed");
} else {
NSLog(@"Request sent");
}
[[NSRunLoop currentRunLoop] run];//How does this work?
});
This code works fine and I get callbacks as expected.
In the documentation https://developer.apple.com/library/ios/documentation/cocoa/Reference/Foundation/Classes/NSRunLoop_Class/Reference/Reference.html#//apple_ref/occ/instm/NSRunLoop/run
It is mentioned that 'run' method, 'Puts the receiver into a permanent loop, during which time it processes data from all attached input sources.'
Now, in above code, I didn't attach any source to the runLoop. How does it work?