Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8856297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:19:30+00:00 2026-06-14T14:19:30+00:00

I wrote a test to experiment with RestKit using blocks. I thought that the

  • 0

I wrote a test to experiment with RestKit using blocks. I thought that the RKRequest.onDidLoadResponse would need to contain a dispatch_async() 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.

My code in question is as follows:

- (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);
            //});
        };
    }];
}

If I uncomment the dispatch_async 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?

I am new to Objective-C and it’s early days for me so I do apologise for what may be a newbie question.

UPDATE: When uncommenting the code above the following happens:

  1. The console outputs the text (lldb) in blue, no other information is provided.
  2. A break on libobjc.A.dylibobjc_msgSend:is shown in the editor on0x1c2009b: movl 8(%edx), %ediwith the message in green:Thread 1: EXC_BAD_ACCESS (code=1, address=0x40000008)`.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:19:31+00:00Added an answer on June 14, 2026 at 2:19 pm

    To answer your question you can check your current thread by calling [NSThread isMainThread]. However, you DONT need to do this for your issue and in fact its perfectly legal to dispatch an execution block to the main thread if you are already running in the main thread.

    The crash is because of the way that variables are stored when executing a block. When the first block is completed the stack memory used by the variable can be overwritten, so by the time your async NSLog statement runs in the second block, your variable res has been destroyed, so its pointing to garbage when its used in your log statement, triggering a crash.

    For completeness, research __block variable declarations. To make res referenceable in your second dispatch block I believe you’d have to declare it as a __block variable to move it to heap by declaring this in your first block: __block RKResponse* response = res; and then using response in your dispatched log statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hї! I have wrote test for my application. I need add item to database
I wrote a test program thinking that the address of p1 will be less
I wrote a small test program for flipperview. I have 3 views. I call
I wrote a feature to test the default configuration of my web app using
I want to test for object references held improperly and wrote a test that
I recently need to build a Expression tree so I wrote a Test method
I wrote a test program that looked like this: #!/usr/bin/python def incrementc(): c =
I am using JUNIT4 + Spring and wrote a test case. I wired in
I wrote Test.java to test out a database connection. I compiled using successfully using
I wrote a test program to monitor my Picture folder which points to c:\users[username]\Pictures

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.