Jonny
Jonny

Reputation: 16298

TWTRSession issue with TwitterKit 3.3.0

let sessions = TWTRTwitter.sharedInstance().sessionStore.existingUserSessions()

supposedly returns an array of TWTRSessions. However the type of the elements is untyped (Any), and casting to TWTRSession using if let authsession = any as? TWTRSession fails. Also, force casting crashes obviously.

let authsession = any as! TWTRSession // crashes

Crash error:

Could not cast value of type 'TWTRSession' (0x103fbe370) to 'TWTRSession' (0x103cf5cc8).

That's a very interesting error, don't you think? TWTRSession matches, but sure, the hex values do not.

Oh, this worked up until before 3.3.0. No release notes or migration notes from the folks at Twitter. Things just silently stopped working.

Related: TWTRTwitter sessionStore now returns TWTRAuthSession: so how does one access the userName property now?

Upvotes: 3

Views: 304

Answers (1)

Alan Zeino
Alan Zeino

Reputation: 4396

I ended up creating a C function to recreate the array and call it from my Swift file:

NSArray<TWTRSession *> *existingUserSessions(TWTRSessionStore *store) {
    NSArray<TWTRSession *> *existingSessions = store.existingUserSessions;
    NSUInteger count = existingSessions.count;
    NSMutableArray<TWTRSession *> *sessions = [NSMutableArray arrayWithCapacity:count];
    for (TWTRSession *session in existingSessions) {
        [sessions addObject:session];
    }
    
    return [sessions copy];
}

Upvotes: 0

Related Questions