"unrecognized selector sent to instance" when creating an NSDictionary with tweets

I am looking for Twitter for tweets using this code:

- (void)fetchTweets
{

NSURL *url = [NSURL URLWithString:@"http://search.twitter.com/search.json"];
NSDictionary *params = [NSDictionary dictionaryWithObject:@"#winning" forKey:@"q"];

TWRequest *request = [[TWRequest alloc] initWithURL:url 
                                         parameters:params 
                                      requestMethod:TWRequestMethodGET];

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

     if (responseData) {
         NSError *jsonError;
         tweets = 
         [NSJSONSerialization JSONObjectWithData:responseData 
                                         options:kNilOptions
                                           error:&jsonError];


         if (tweets) {
            // NSLog(@"%@", tweets);
         } 

         else { 
             NSLog(@"%@", jsonError);
         }

     }

     [[self delegate] receivedTweets];

 }];

[self performSelector:@selector(fetchTweets) withObject:nil afterDelay:30];

The tweets variable is an NSArray, and I'm trying to put it in an NSDictionary with this code:

NSDictionary *tweet = [[TwitterHandler sharedInstance].tweets objectAtIndex:indexPath.row];

I definitely get JSON text for tweets, but when I try to add them to the dictionary so that I can eventually put them in a table, I get the error "unrecognized selector sent to instance."

I am not sure why I get this and any help would be appreciated.

+3
source share
3 answers
[NSJSONSerialization JSONObjectWithData:responseData 
                                options:kNilOptions
                                  error:&jsonError];

This returns an NSDictionary object for tweets. Twitter search results at this URL can be filtered by searching for content in a key results.

AKA:

NSDictionary *jsonTweet = [NSJSONSerialization JSONObjectWithData:responseData 
                                                          options:kNilOptions
                                                          error:&jsonError];

NSArray *tweet = [jsonTweet objectForKey:@"results"];

, NSArray.

+1

:

 if (responseData) {
         NSError *jsonError;
         tweets = 
         [NSJSONSerialization JSONObjectWithData:responseData 
                                         options:kNilOptions
                                           error:&jsonError];


         if (tweets) {
            // NSLog(@"%@", tweets);
         } 

         else { 
             NSLog(@"%@", jsonError);
         }

tweets , :

[[TwitterHandler sharedInstance].tweets

, , au autoreleased object, , .

.

-

tweets = 
         [[NSJSONSerialization JSONObjectWithData:responseData 
                                         options:kNilOptions
                                           error:&jsonError] retain];

, , tweets orpperty:

self.tweets = 
         [NSJSONSerialization JSONObjectWithData:responseData 
                                         options:kNilOptions
                                           error:&jsonError];

, ( , dealloc )

, , ( !): URL-, :

{"error":"You must enter a query."}

JSon. JSON Parser . NSArray *, NSDictionary. , , .

+2

I had this once and it was the application that released the view controller, check if your view controller is freed.

+1
source

All Articles