Search code examples
iphonensdictionarymgtwitterengine

Items in NSDictionary returns NULL


I'm using MGTWitterEngine and I cannot figure out why my dictionary items are returning null.

I have this method:

- (void)searchResultsReceived:(NSArray *)searchResults forRequest:(NSString *)connectionIdentifier{
NSDictionary *result = [searchResults objectAtIndex:0];
NSString *fromUser = [result valueForKey:@"from_user"];
NSLog(@"from user: %@", fromUser);
}

And for some reason, my NSLog always displays "from user: NULL". I can do an NSLog of searchResults which dumps the contents of the search correctly, but I can't figure out how to parse the information. Any help would be greatly appreciated.


Solution

  • Look at this question: Parsing Search Result with MGTwitterEngine in Objective C

    They use:

    - (void)searchResultsReceived:(NSArray *)searchResults 
                       forRequest:(NSString *)connectionIdentifier
    {
        if ([searchResults count] > 0)
        {
            NSDictionary *result = [searchResults objectAtIndex:0];
    
            NSString *fromUser = [result valueForKey:@"from_user"];
            NSString *fromUserID = [result valueForKey@"from_user_id"];
            // ...
            NSString *text = [result valueForKey@"text"];
    
            NSLog(@"User %@(%@): %@", fromUser, fromUserID, text);
        }
    }
    

    It is similar to your code with a check on searchResults count.