title: Twitter search for hashtag
body: <p>I'm trying to parse tweets using <strong>Twitter Framework</strong>, so I write the following code and it's working fine, but it's not <strong>Synchronous</strong>.</p>
  
  <blockquote>
    <p>Now I'm trying to get all the tweets from #iOS.</p>
  </blockquote>
  
  <p>I have used the following code to get the search result for iOS hashtag:</p>
  
  <pre><code>-(void)fetchResults
  {
      // Do a simple search, using the Twitter API
      TWRequest *request = [[TWRequest alloc] initWithURL:[NSURL URLWithString:
                                                           @"http://search.twitter.com/search.json?q=iOS%20&amp;rpp=20&amp;with_twitter_user_id=true&amp;result_type=recent"]
                                               parameters:nil requestMethod:TWRequestMethodGET];
  
      // Notice this is a block, it is the handler to process the response
      [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
      {
          if ([urlResponse statusCode] == 200)
          {
              // The response from Twitter is in JSON format
              // Move the response into a dictionary and print
              NSError *error;
              dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&amp;error];
              NSLog(@"Twitter response: %@", [dict description]);
              [self filterTweets];
  
          }
          else
              NSLog(@"Twitter error, HTTP response: %i", [urlResponse statusCode]);
      }];
  
  }
  </code></pre>
  
  <p>As a result I got this:</p>
  
  <pre><code>Twitter response: {
  "completed_in" = "0.007";
  "max_id" = 333837474914766848;
  "max_id_str" = 333837474914766848;
  page = 1;
  query = quranRadios;
  "refresh_url" = "?since_id=333837474914766848&amp;q=quranRadios&amp;result_type=recent";
  results =     (
              {
          "created_at" = "Mon, 13 May 2013 06:53:51 +0000";
          "from_user" = YousefMutawe;
          "from_user_id" = 324385406;
          "from_user_id_str" = 324385406;
          "from_user_name" = "Yousef N Mutawe \Uf8ff";
          geo = "&lt;null&gt;";
          id = 333837474914766848;
          "id_str" = 333837474914766848;
          "iso_language_code" = pt;
          metadata =             {
              "result_type" = recent;
          };
          "profile_image_url" = "http://a0.twimg.com/profile_images/1533729607/20090719526_normal.jpg";
          "profile_image_url_https" = "https://si0.twimg.com/profile_images/1533729607/20090719526_normal.jpg";
          source = "&amp;lt;a href=&amp;quot;http://twitter.com/download/iphone&amp;quot;&amp;gt;Twitter for iPhone&amp;lt;/a&amp;gt;";
          text = "Testing #quranRadios @Mkalatrash";
      },
              {
          "created_at" = "Sun, 12 May 2013 13:09:43 +0000";
          "from_user" = YousefMutawe;
          "from_user_id" = 324385406;
          "from_user_id_str" = 324385406;
          "from_user_name" = "Yousef N Mutawe \Uf8ff";
          geo = "&lt;null&gt;";
          id = 333569679484416000;
          "id_str" = 333569679484416000;
          "iso_language_code" = et;
          metadata =             {
              "result_type" = recent;
          };
          "profile_image_url" = "http://a0.twimg.com/profile_images/1533729607/20090719526_normal.jpg";
          "profile_image_url_https" = "https://si0.twimg.com/profile_images/1533729607/20090719526_normal.jpg";
          source = "&amp;lt;a href=&amp;quot;http://twitter.com/download/iphone&amp;quot;&amp;gt;Twitter for iPhone&amp;lt;/a&amp;gt;";
          text = "#quranRadios :)";
      }
  );
  "results_per_page" = 20;
  "since_id" = 0;
  "since_id_str" = 0;
  </code></pre>
  
  <p>}</p>
  
  <p>So i use the following method to filter the result and to get the (Tweet,Username,and the User image):</p>
  
  <pre><code>-(void)filterTweets
  {
      NSArray *results = [dict objectForKey:@"results"];
  
      //Loop through the results
      int x =0;
      for (NSDictionary *tweet in results)
      {
          // Get the tweet
          NSString *twittext = [tweet objectForKey:@"text"];
          NSString *twitPic = [tweet objectForKey:@"profile_image_url"];
          NSString *userName = [tweet objectForKey:@"from_user"];
          // Save the tweet to the twitterText array
          [tweetsInfo addObject:(twittext)];
          [tweetPics addObject:(twitPic)];
          [imagesArray addObject:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[tweetPics objectAtIndex:x]]]]];
          [userNameTweet addObject:userName];
          x++;
      //NSLog(@"tweet ooooooo ======&gt; %@",twitPic);
          countMe++;
      }
  [tweetsTable reloadData];
  }
  </code></pre>
  
  <p>I'm not sure if i'm doing the right thing,so what would you recommend me to do? and how can i make it synchronized? </p>
  
  <blockquote>
    <p>am new to programming iOS, please advice.
    Thanks.</p>
  </blockquote>