Pre-calculating the layout

To figure out how to calculate the layout for your collection view, you can use a playground to quickly test and iterate over your attempts at calculating a layout, without the overhead of having to run an app first. Playgrounds are a fantastic way to test, explore, and validate ideas you have quickly. Since playgrounds don't need an entire app to run, they provide immediate feedback, something you don't get when you usually build and run a project. Create a new playground by navigating to File | New | Playground. Create a new playground and name it something like LayoutExploration.

The collection view should display as many items as possible, so the first step when calculating the layout is to determine how many ...

Get Mastering iOS 12 Programming - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.