Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

alonecuzzo

macrumors newbie
Original poster
Dec 21, 2010
3
0
I'm using SA_OAuthTwitterEngine. It's basically a wrapper for the MGTwitterEngine. I would like to create a single instance of the engine and then use it throughout my app.

I created a singleton instance of my own TwitterEngineInstance class that holds the engine instance, but the engine can only be instantiated with a single delegate. There are no built in methods to overwrite the delegate in the MGTwitterEngine so I feel like I'm using it wrong.

I have to change delegates when I change pages. I have a main feed page which works fine, but then I click to my Direct Messages page, I have to pass that view controller as the delegate but there's no easy way to do this. Right now I'm destroying my singleton and then re-instantiating it with my new delegate which works, but I have to login again to twitter.

I'd rather not build a method in the MGTwitterEngine that swaps delegates. I feel like the creator would've stuck that in there if I were viewing things right, but I think I'm seeing things wrong. Anyone have any experience with this?

Thanks!
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
What functionality are you delegating? Would it be easier for you to delegate to a small wrapper that has its own easily-swapped delegate?

-Lee
 

alonecuzzo

macrumors newbie
Original poster
Dec 21, 2010
3
0
Smart. I think it makes more sense to do that. I was delegating the response to the getDirectMessages method to my initial viewcontroller. But I swap views so the initial delegate was sticking. I ended up modding the Twitter engine class to allow me to swap delegates easily, but I think your suggestion is way better since it doesn't involve me modding the library code.

Thx!:)
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
A possible issue would be a breakdown in the ability to check if your delegate responds to a particular message. If you only implement one method, and every delegate you set responds to this message, you're fine. You'd hit a bit of a snag if you implemented many methods in your wrapper, but not every possible delegate you give it responds to all of these messages. When asked your delegate would say it responds, but its delegate does not. This may short-circuit the "default" behavior in the library class.

You could get tricky with resolveInstanceMethod: but... Well, it might be a little much.

-Lee
 

alonecuzzo

macrumors newbie
Original poster
Dec 21, 2010
3
0
Ah okay I think I follow. I read up on the resolveInstanceMethod. That basically would allow me to swap delegate methods in my delegate wrapper based on which event bubbled up from the main twitter engine right?
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
It might be difficult to game the dynamic resolution based on your delegate, but it might be possible. I actually don't know if you can remove a method after you've added it, so that could prevent this from working.

If the default behavior of these methods is to do nothing if the delegate doesn't respond there's nothing to worry about. I was just trying to point out a gotcha with the suggestion. A setDelegate: on the original library object would definitely be nice. You might be able to add one with a category, but it would require knowing the name of the member/property of the delegate, which could change.

-Lee
 

cye

macrumors newbie
Sep 8, 2010
5
0
Texas
Alonecuzzo, I'm currently having the exact same problem that you did. I'm using SA_OAuthTwitterEngine and I created a singleton instance of it, but I have to login everytime I switch views. How did you end up solving it?
 

cye

macrumors newbie
Sep 8, 2010
5
0
Texas
I'm using SA_OAuthTwitterEngine. It's basically a wrapper for the MGTwitterEngine. I would like to create a single instance of the engine and then use it throughout my app.

I created a singleton instance of my own TwitterEngineInstance class that holds the engine instance, but the engine can only be instantiated with a single delegate. There are no built in methods to overwrite the delegate in the MGTwitterEngine so I feel like I'm using it wrong.

I have to change delegates when I change pages. I have a main feed page which works fine, but then I click to my Direct Messages page, I have to pass that view controller as the delegate but there's no easy way to do this. Right now I'm destroying my singleton and then re-instantiating it with my new delegate which works, but I have to login again to twitter.

I'd rather not build a method in the MGTwitterEngine that swaps delegates. I feel like the creator would've stuck that in there if I were viewing things right, but I think I'm seeing things wrong. Anyone have any experience with this?

Thanks!

I know I'm reviving an old thread here, but how did you end up fixing it?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.