Twitter Access, MGTwitterEngine

Discussion in 'Mac Programming' started by alonecuzzo, Dec 21, 2010.

  1. alonecuzzo macrumors newbie

    alonecuzzo

    Joined:
    Dec 21, 2010
    #1
    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!
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    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
     
  3. alonecuzzo thread starter macrumors newbie

    alonecuzzo

    Joined:
    Dec 21, 2010
    #3
    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!:)
     
  4. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    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
     
  5. alonecuzzo thread starter macrumors newbie

    alonecuzzo

    Joined:
    Dec 21, 2010
    #5
    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?
     
  6. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #6
    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
     
  7. cye macrumors newbie

    Joined:
    Sep 8, 2010
    Location:
    Texas
    #7
    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?
     
  8. cye macrumors newbie

    Joined:
    Sep 8, 2010
    Location:
    Texas
    #8
    I know I'm reviving an old thread here, but how did you end up fixing it?
     

Share This Page