UICollectionView has the task of figuring out how to best place the cells you give it within its view. As we've seen in other videos, if they're small cells compared to the view, it just fits them in and wraps them around until it's full, and then it starts to scroll so you can see all of them. Well, with us, we want to kind of trick the view into making a swiping menu like you see, so we force the width of the cell to be the view's width (not counting the padding for now). If we did that, we could find that if we wanted three cells to appear at a time, then we would want to make sure that they were just tall enough so that the UICollectionView would fit three in there without pushing the third one to the next column.
The hard part about the math at the end (just guessing what you're thinking) is that you now have padding so the cells look separate. Brian is doing what in math is called "parameterization" in the sense that he wants to be able to set the functions up so you can just change one or two variables and have the cells size themselves so they'll fit well.
We know we want three, and Brian wisely created "topBottomPadding" and "lineSpacing". That means that he needs to make up an equation that will be able to tell the UICollectionView how tall the cells will be so that it all fits perfectly. Now, we have two methods that control the spacing inbetween the cells, one is set to "lineSpacing" and one uses edge insets to pad the top and bottom. It might help to draw a box and make a little box within the box with those insets on some paper. We're left with a smaller box inside. The other method says that there needs to be spaces inbetween the cells, and that "lineSpacing". So, we're left with a height that needs to be divided up so that there are three cells and that min line spacing.
So, on line 40: (almost done) we take the total height. We take away the top and bottom padding twice. We know that three cells will have two gaps in between them, so we take away the line spacing twice, as well. That leaves us with a certain amount of height left over, that we then split up three ways at the end. That three way split gets sent to the UICollectionView, and when it puts it all together, it looks just like Brian has it.
Hope that helps.