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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:44:06+00:00 2026-05-27T19:44:06+00:00

I was trying to work on xcode and ios5 and I have a TWRequest

  • 0

I was trying to work on xcode and ios5 and I have a TWRequest to bring down tweets using the Twitter Api. However, I am confused about how blocks work in iOS5. For example in this code

 [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {

    NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];
    NSArray* firstParse = [dictionary objectForKey:@"results"];

    for (NSDictionary *post in firstParse) {               
        Tweet *tweetMessage = [[Tweet alloc] init];
        tweetMessage.message =  [post objectForKey:@"text"];
        tweetMessage.user =  [post objectForKey:@"from_user"];

        [tweets addObject:tweetMessage];
    }
}];
NSLog(@"%@",[tweets count]);

Assuming that I have a tweets = [NSMutableArray arrayWithCapacity:25]; call somewhere up top.

However, every time I do this, the count is always at zero. After doing some testing, I realized that the block code was running after the NSLog was running signifying that the code did not run from top down as I was use to.

Does anyone know how to fix such an issue?

I also tried this later example because I was trying to move the tweets into a viewController that has an array object

tweetViewController.tweets = [NSMutableArray arrayWithCapacity:25];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {

    NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];
    NSArray* firstParse = [dictionary objectForKey:@"results"];

    for (NSDictionary *post in firstParse)
    {               
        Tweet *tweetMessage = [[Tweet alloc] init];
        tweetMessage.message =  [post objectForKey:@"text"];
        tweetMessage.user =  [post objectForKey:@"from_user"];

        [tweetViewController.tweets addObject:tweetMessage];

        NSLog(@"%d",[tweets count]);
        //NSLog(@"%@: %@", [post objectForKey:@"from_user"], [post objectForKey:@"text"]);            
    }
}];

Tweet *tweetMessage = [[Tweet alloc] init];
tweetMessage.message =  @"HELLO";
tweetMessage.user =  @"HELLO";
[tweetViewController.tweets addObject:tweetMessage];
return YES;

The Hello messages display properly but the ones in the block do not.

  • 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-27T19:44:07+00:00Added an answer on May 27, 2026 at 7:44 pm

    Don’t. Basically, focus on making your code asynchronous. This’ll be better for the user (the UI will be more smooth) and easier for the developer (yes, really!)

    Do everything that’s related to loading the tweets in the block instead of after it. Place your NSLog in the block instead of outside it. Once you’re done loading all the tweets, simply call [tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; or something else, to update the UI.

    Make sure to avoid using the nonatomic flag on the property that stores the tweets. You want to avoid invalid cross-thread access.

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

Sidebar

Related Questions

Using Xcode/Cocoa and the ExtAudioFile API, I'm trying to store away AudioBufferList* objects away
I have been trying to work my way through Project Euler, and have noticed
I'm trying to create a Java Tool by using Xcode. I've already changed my
I'm trying to debug in XCode using the instruments but most of them are
Using the basic starting app from XCode for a navigation based application, I'm trying
Using Xcode 4.x I created a SplitView project for iPad From RootViewController I'm trying
Anyone get iCuke to work with XCode 4? I'm trying to follow the iCuke
So I've been trying to get dynamic libraries to work in my XCode project
I have been trying to replace everything in xcode with stuff I can get
I`m trying to customize my TabBar in xcode,ios, however I just found ppl saying

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.