Final words on the custom layout

The custom layout that was created in this subsection is a great example of the powers of UICollectionView. However, with great power comes great responsibility. The implementation that's provided isn't entirely reusable since it doesn't deal with headers or multiple sections. If you're building your own app, this might be completely fine. If all you'll ever deal with is a single array of items that isn't divided in sections or uses decoration views, you'll be good. However, if you want to create a layout that can be reused and is ready for anything, you should take care of implementing all of the methods that can affect layout.

More importantly, even simple layouts can make an otherwise fast collection view really slow. It's very easy to do a recursive or complex calculation that will run more times than needed, resulting in a collection view that will scroll exponentially slower until it won't scroll at all. These situations are frustrating for users, and instead of praising you and your creative layout, they will be annoyed by it.

If you are able to properly create and implement a beautiful custom layout, you have a very powerful tool in your toolbox. You know now that implementing something different than a standard grid isn't rocket science and the implementation isn't overly complex. With some careful planning and experimenting in playgrounds, you can make amazing layouts for your users.

Reader exercise: The current layout is aligned to the top of the collection view and fills up the view as much as possible. There is space left at the bottom. A great exercise is to adapt the layout to be centered vertically within the collection view. You will need to change the layout preparation method and the layout invalidation method. Good luck!