Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I know if I am executing something on the UI thread?
    text
    copied!<p>I wrote a test to experiment with RestKit using blocks. I thought that the <code>RKRequest.onDidLoadResponse</code> would need to contain a <code>dispatch_async()</code> call to get the response on the main UI thread, though to my surprise this turned out to cause a runtime exception, so I took it out and I could update the interface quite fine.</p> <p>My code in question is as follows:</p> <pre><code>- (IBAction)loadSeasons:(UIButton *)sender { [[RKClient sharedClient] get:@"/api/v1/seasons" usingBlock:^(RKRequest* req) { req.onDidLoadResponse = ^(RKResponse* res) { NSLog(@"Request Performed: %@", res.bodyAsString); self.textResponse.text = res.bodyAsString; //dispatch_async(dispatch_get_main_queue(), ^{ // NSLog(@"In main queue: %@", res.bodyAsString); //}); }; }]; } </code></pre> <p>If I uncomment the <code>dispatch_async</code> block I get the exception. So how do I know when I need to use this and when I should not need to? Should I test for something that tells me if the code being executed is on the main thread or not?</p> <p>I am new to Objective-C and it's early days for me so I do apologise for what may be a newbie question.</p> <p><strong>UPDATE</strong>: When uncommenting the code above the following happens:</p> <ol> <li>The console outputs the text <code>(lldb)</code> in blue, no other information is provided.</li> <li>A break on <code>libobjc.A.dylib</code>objc_msgSend:<code>is shown in the editor on</code>0x1c2009b: movl 8(%edx), %edi<code>with the message in green:</code>Thread 1: EXC_BAD_ACCESS (code=1, address=0x40000008)`.</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload