Search code examples
iphoneobjective-cmgtwitterengine

Returning statuses from MGTwitterEngine


I am using MGTwitterEngine in an iPhone application to make a simple call for user statuses. The engine has a delegate method:

- (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)identifier

And I can see my statuses logged in the console. My question is what is the best way to then use the statuses and be informed when they have been received?

I suspect this might be more about how to use the delegate pattern properly.

Thanks,


Solution

  • I went with setting up an NSNotification observer and then calling that from statusesReceived:forRequest. I also set an NSArray iVar in the delegate method which I access in my NSNotification callback:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tweetNotificationHandler:) name:@"tweetsArrived" object:nil]; 
    
    - (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)identifier{
    
    tweets = statuses; //this is an ivar
    
    NSNotification* notification = [NSNotification notificationWithName:@"tweetsArrived" object:self];
    [[NSNotificationCenter defaultCenter] postNotification:notification];
    
    }
    
    -(void)tweetNotificationHandler: (NSNotification*)notification   {
    //do your results handling here.
    }