It’s always funny to me to look at our app metrics and see what versions are still being used. Noticed today that a version is still being used that was released in 2019. But they are running iOS 16. I guess app updates aren’t as important as iOS updates. 😂

It does make me feel bad knowing that their version is about to break. 😔

Trouble with NSDiffableDataSourceSectionSnapshot

I’m running into issues when trying to use NSDiffableDataSourceSectionSnapshot. I want to have this UI, where we have multiple sections and each section has builds, but the additional builds are collapsible. This works, however, since there are a large number of sections there is some significant UI hangs. I played around with the number of sections and the magic number appears to be 80. 80 sections or less and there are no UI hangs, but anything over that will experience a hang.

Here is the snapshot code that I am using to generate the section snapshots.

        if snapshot().sectionIdentifiers != sections.map(\.branch) {
            var snapshot = Snapshot()
            snapshot.appendSections(sections.map(\.branch))
            apply(snapshot, animatingDifferences: animatingDifferences)
        }

        sections.forEach { section in
            var sectionSnapshot = SectionSnapshot()

            if let currentBuild = section.builds.first.map({ SectionItem.currentBuild($0) }) {
                sectionSnapshot.append([currentBuild])
            }

            if section.builds.count > 1 {
                let additionalBuildsHeader = SectionItem.additionalBuildsHeader(forSection: section.branch)
                sectionSnapshot.append([additionalBuildsHeader])
                let additionalBuilds = section.builds
                    .dropFirst()
                    .map({ SectionItem.additionalBuild($0) })
                sectionSnapshot.append(additionalBuilds, to: additionalBuildsHeader)

                if expandedSections.contains(additionalBuildsHeader) {
                    sectionSnapshot.expand([additionalBuildsHeader])
                }
            }
            apply(sectionSnapshot, to: section.branch, animatingDifferences: animatingDifferences)
        }

After some tinkering we discovered that building the snapshot without using a section snapshot loaded the UI without any issues. This works, and I am ok with this approach. We just loose the nice collapsible section for the additional builds.

        var snapShot = Snapshot()
        snapShot.appendSections(sections.map(\.branch))

        sections.forEach { section in
            if let currentBuild = section.builds.first.map({ SectionItem.currentBuild($0) }) {
                snapShot.appendItems([currentBuild], toSection: section.branch)
            }

            if section.builds.count > 1 {
                let additionalBuilds = section.builds
                    .dropFirst()
                    .map({ SectionItem.additionalBuild($0) })
                snapShot.appendItems(additionalBuilds, toSection: section.branch)
            }
        }
        apply(snapShot, animatingDifferences: animatingDifferences)

I feel that this is related to calling apply many times for the section snapshots as opposed to one apply in the second example. Am I doing something wrong with the section snapshots that is causing the bad performance?

It is definitely a case of the Mondays today. I was thinking that I broke push notifications, only to realize that I was using the device token from the simulator instead of from my device. 🤦🏼‍♂️

What a way to start a Monday. Could not remember how to pass a type as a function parameter and had to look it up to remind myself to add .Type. How’s your Monday going? 🤦🏼‍♂️

My stress eating food of choice today is salted chips. I have almost eaten this entire bag today.

I’ve managed to survive the annual work password reset without locking myself out. 🎉

That’s two days in a row that I’ve slept through my alarm. I think my body is protesting getting started in the new year. 🥱 😴

Time for the annual forget your work password after returning from Christmas vacation.

Happy new year! 🎊🎆 Frohes neues Jahr!

Got one of the coolest gifts ever this year. 😁

Merry Christmas everyone. Hope that you are having a good holiday. 🎄🎅🏼

Slowly but surely I am learning to bend UICollectionViewDiffableDataSource to my will. Still have a lot to learn, but figuring out the best way to structure the data for the snapshots has been my biggest challenge. Not making the section identifier as simple as possible initially was my biggest mistake.

Staring at a newly created project in Xcode is, to me, like a writer staring at a blank piece of paper.

It’s definitely going to be some kind of day when the car driving down the street is blasting “Ice Ice Baby” at 8:30 in the morning. 😁

How has it taken me this long to discover the magic of fleece lined jeans for winter? These things are amazing and so comfortable.

Emma’s sleep schedule has been adjusting lately. No matter what time she goes to bed, she is now waking up between 6 and 6:30 instead of 7 and 7:30. I’m missing that extra hour of sleep. 🥱

Number of days that I forgot to set translatesAutoresizingMaskIntoConstraints to false? Zero. 🤦🏼‍♂️

Falling down the rabbit hole of refactoring some code thinking that it can, or should, be cleaned up a bit only to end up back where I started and realizing that this approach is perfectly fine.

I spent an embarrassing amount of time, this morning, trying to figure out why my collection view cells weren’t refreshing when I updated the snapshot. Only to realize that I had added a custom equatable function to the struct that was only checking the id value, which doesn’t change. 🤦🏼‍♂️

I really enjoyed giving a talk at our Tech Get Together at trivago. Something that has been terrifying to me, as I hate speaking in front of a lot of people. But I really enjoyed the experience and it was a lot of fun. I was mentally exhausted last night, after having been stressed over this for a few weeks. On the bright side, I slept really well.