Search code examples
swifttvosdiffabledatasource

tvOS 13 DiffableDataSource Invalid parameter not satisfying: itemCount


When launching my tvOS application I'm getting a crash related to the DiffableDataSource: Thread 1: Expection: "Invalid parameter not satisfying: itemCount".

It's occurring on the line dataSource.apply(snapshot).

When trying to run this on Xcode 12 beta 4 I get the following crash:

Thread 1: "Invalid update: invalid number of sections. The number of secxtions contained in the collection view after the update (1) must be equal to the number of sections contained in the collection view before hte update (1), plus or minus the number of sections inserted or deleted (1 inserted, 0 deleted)."

Which is more detailed, but still doesn't give information as to why this would be occurring.

The same code runs fine on iOS.

Why would this be occuring?


Solution

  • The solution in this case is to move the dataSource code out of viewDidLoad and into viewDidAppear.

    It looks like it has to do with some timing problem or something on tvOS, and truly looks to be a bug in the SDK.