Chapter 23 - RxDataSource duplicates fatal error

Hey,

After completing the last challenge in chapter 23, I observer a fatal error while I stay in ListTimelineViewController for 30 seconds, because of tweet duplicates passed to the data source of the table view. I think the timer update leads to duplicates passed to the tweets observable in ListTimelineViewModel. What approach can I take to resolve this issue?

@icanzilb Could you please help with this when you get a chance? Thank you - much appreciated! :]

@axelsyrex could you provide the error message you’re getting please?

@icanzilb
This is the raw error I get in the console.

fatal error: Duplicate item Tweet {
id = 883323617857216513;
text = @fpillet @icanzilb Even better and super hyped: delete the Facebook account. :sunglasses:;
name = Junior B.;
created = 2017-07-07 13:55:36 +0000;
imageUrl = https://pbs.twimg.com/profile_images/679331191577821185/PnwteIfj_normal.png;
}: file /Users/Saho/Documents/Docs/Books/RxSwift_v1.1/23-mvvm-with-rxswift/challenge/Tweetie/Pods/RxDataSources/Sources/DataSources/DataSources.swift, line 31

@axelsyrex I tried the project included in the book, navigated back and forth few times between screens and left the sim running for about 10 minutes but cannot reproduce this error. Maybe you can also give the completed project included in the book a try and let us know if you still see the error?

@icanzilb The crash appears only while in PersonTimelineViewController(iOS folder) inside the challenges project, which I have not touched at all. Have you tried that one as well?

1 Like

Aha! Found it … ok, I’ll have a look what is it all about and let you know

@axelsyrex great catch! the starter project includes the bug you describe, in TwitterAPI.swift there’s a method that returns the tweets in given user’s timeline - and this method gets a timeline cursor as a parameter but does not actually use the cursor to fetch only the latest tweets … that’s why the method returns duplicate tweets.

We will fix that in the next edition of the book (thank you!) but for now you can fix it yourself. Open TwitterAPI.swift and modify the first class method as follows:

static func timeline(of username: String) -> (ACAccount, TimelineCursor) -> Observable<[JSONObject]> {
return { account, cursor in
    var params = ["screen_name": username, "contributor_details": "false", "count": "100", "include_rts": "true"]
    if cursor != TimelineCursor.none {
        params["max_id"]   = String(cursor.maxId)
        params["since_id"] = String(cursor.sinceId)
    }
    return request(account, address: TwitterAPI.Address.timeline, parameters: params)
}
}

Thank you for the update @icanzilb!

PS. The book helped me big time for starting reactive development, you did a great job!

This topic was automatically closed after 166 days. New replies are no longer allowed.