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 6612717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:07:53+00:00 2026-05-25T20:07:53+00:00

For some reason this code does not work: [request setCompletionBlock:^{ NSString *response = [request

  • 0

For some reason this code does not work:

[request setCompletionBlock:^{
    NSString *response = [request responseString];
    NSDictionary *data = [response JSONValue];
    NSArray *events = (NSArray *)[data objectForKey:@"objects"];

    for (NSMutableDictionary *event in events){

        /* experimental code*/
        NSString *urlString = [NSString 
                               stringWithFormat:
                               @"http://localhost:8000%@?format=json",
                               [event objectForKey:@"tournament"]];

        NSURL *url2 = [NSURL URLWithString:urlString];
        ASIHTTPRequest *request2 = [ASIHTTPRequest requestWithURL:url2];
        [request2 setCompletionBlock:^{
            NSString *responseString = [request2 responseString];
            NSDictionary *tournamentDict = [responseString JSONValue];
            self.tournamentString = [tournamentDict objectForKey:@"tournament"]; 
        }];
        [request2 startAsynchronous];

        /* end experimental code */
        NSLog(@"%@", self.tournamentString);
        [mutableArray addObject:event];
    }
    self.eventsArray = mutableArray;
    [MBProgressHUD hideHUDForView:self.view animated:YES];

    [self.tableView reloadData];
}];

so here are 2 asynchronous requests, in which I fire one after another. I want to change the value of the property tournamentText after the second request executes.

Inside the completion block for the second request, when I NSLog self.tournamentText, it displays the text I want to retrieve.

Outside the block, an NSLog produces a nil.

What can I do to preserve the changes to self.tournamentText? Thanks in advanced! Please do tell me if I missed an Apple documentation on this.

  • 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-05-25T20:07:54+00:00Added an answer on May 25, 2026 at 8:07 pm

    You should probably apply the __block storage type modifier to the variable (outside of the block).

    __block NSDictionary *tournamentDict;

    See Apple’s documentation on interaction between blocks and variables (in Blocks Programming Topics) for more info.

    By the way, you do realize that you have a block within a block, rather than two separate blocks after another? To preserve the changes to the variable outside the second block, try this:

    [request setCompletionBlock:^{
        NSString *response = [request responseString];
        NSDictionary *data = [response JSONValue];
        NSArray *events = (NSArray *)[data objectForKey:@"objects"];
    
        for (NSMutableDictionary *event in events){
    
            /* experimental code*/
            NSString *urlString = [NSString 
                                   stringWithFormat:
                                   @"http://localhost:8000%@?format=json",
                                   [event objectForKey:@"tournament"]];
    
            NSURL *url2 = [NSURL URLWithString:urlString];
            ASIHTTPRequest *request2 = [ASIHTTPRequest requestWithURL:url2];
            __block NSDictionary *tournamentDict;
            [request2 setCompletionBlock:^{
                NSString *responseString = [request2 responseString];
                tournamentDict = [responseString JSONValue];
                self.tournamentString = [tournamentDict objectForKey:@"tournament"]; 
            }];
            [request2 startAsynchronous];
    
            /* end experimental code */
            NSLog(@"%@", self.tournamentString);
            [mutableArray addObject:event];
        }
        self.eventsArray = mutableArray;
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    
        [self.tableView reloadData];
    }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, this code does not actually draw my bitmap file... or show
For some reason the following code does not work as expected when in IE
For some reason this PHP code below will not work, I can not figure
For some reason, the following code does not work: char cValue = '8'; int
Why does this code not work? echo explode(?, $_SERVER[REQUEST_URI])[0]; It says syntax error, unexpected
For some reason the script below is not working. This is the code I
this code was just working! but for some reason it stopped to work now.
For some reason my code here (this is the entire thing) doesnt actually render
For some reason this program is saying that 'switch' is not defined. What is
Im using oslib with the pspsdk toolchain and for some reason this doesnt work

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.