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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:50:19+00:00 2026-06-04T11:50:19+00:00

Possible Duplicate: returning UIImage from block Hi I’m trying to return dictionary of json

  • 0

Possible Duplicate:
returning UIImage from block

Hi I’m trying to return dictionary of json twitter data so i can use it in my application. How ever it is being called from a async block. I can not save it or return it any thoughts?

  -(NSDictionary *)TweetFetcher
    {

    TWRequest *request = [[TWRequest alloc] initWithURL:
                          [NSURL URLWithString: @"http://search.twitter.com/search.json?
    q=iOS%205&rpp=5&with_twitter_user_id=true&result_type=recent"] parameters:nil 
    requestMethod:TWRequestMethodGET];


    [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse 
    *urlResponse, 
    NSError *error)
     {
         if ([urlResponse statusCode] == 200) 
         {
             NSError *error;        
             NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseData 
             options:0 error:&error];


             //resultsArray return an array [of dicitionaries<tweets>];
             NSArray* resultsArray = [dict objectForKey:@"results"]; 
             for (NSDictionary* internalDict in resultsArray)

                 NSLog([NSString stringWithFormat:@"%@", [internalDict 
             objectForKey:@"from_user_name"]]);
        ----> return dict; // i need this dictionary of json twitter data
         }
         else
             NSLog(@"Twitter error, HTTP response: %i", [urlResponse statusCode]);
         }];
      }

Thnx in advance!

  • 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-04T11:50:20+00:00Added an answer on June 4, 2026 at 11:50 am

    I feel like I’ve written a ton of this async code lately.

    - (void)tweetFetcherWithCompletion:(void(^)(NSDictionary *dict, NSError *error))completion
    {
        NSURL *URL = [NSURL URLWithString:@"http://search.twitter.com/search.json?q=iOS%205&rpp=5&with_twitter_user_id=true&result_type=recent"];
        TWRequest *request = [[TWRequest alloc] initWithURL:URL parameters:nil requestMethod:TWRequestMethodGET];
    
        [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
            if ([urlResponse statusCode] == 200) {
                NSError *error;
                NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];
    
                if (error) {
                    completion(nil, error);
                    return;
                }
    
                //resultsArray return an array [of dicitionaries<tweets>];
                NSArray* resultsArray = [dict objectForKey:@"results"]; 
                for (NSDictionary* internalDict in resultsArray)
                    NSLog(@"%@", [internalDict objectForKey:@"from_user_name"]);
    
                completion(dict, nil);
            }
            else {
                NSLog(@"Twitter error, HTTP response: %i", [urlResponse statusCode]);
                completion(nil, error);
            }
        }];
    }
    

    So, instead of calling self.tweetDict = [self TweetFetcher];, you would call it this way.

    [self tweetFetcherWithCompletion:^(NSDictionary *dict, NSError *error) {
        if (error) {
            // Handle Error Somehow
        }
    
        self.tweetDict = dict;
        // Everything else you need to do with the dictionary.
    }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why can you return from a non-void function without returning a value
Possible Duplicate: Why can you return from a non-void function without returning a value
Possible Duplicate: Returning unique_ptr from functions 20.7.1.2 [unique.ptr.single] defines copy constructor like this :
Possible Duplicate: Returning a reference can work? Why this code works ( matrix is
Possible Duplicate: Returning a value from thread? I have this code: //Asynchronously start the
Possible Duplicate: returning multiple values from a function Suppose i have passed two values
Possible Duplicate: How to format a JSON date? My webs service is returning a
Possible Duplicate: why isn't this pulling data from 7 days back? Here is what
Possible Duplicate: Returning multiple values from a C++ function /************************************************/ /* Name: premserv */
Possible Duplicate: Returning the address of local or temporary variable Can a local variable's

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.