
These custom types makes it possible to use ForEach
in the new Grid
layout, because each GridRowContent
and each GridItemContent
conform to Identifiable
. This makes them unique, even though the data I’m using is just strings that wouldn’t be Identifiable
on their own. To make the initialiser easier to use I’ve allowed an array of strings to be passed in, which are then mapped to a GridItemContent
object that holds their value and identifies them uniquely.
I’m going to use letters of the alphabet as my data, primarily because using this many full words makes the grid a bit crowded on small screens. The interface for this is very simple, I simply wanted to have a variable number of grid rows that wasn’t determined by the view body. I haven’t made rows
into a State
, Binding
or Published
property so it can’t be changed, but it’s easy to see how this could be used with data that changes at runtime.
Support Type Safely
You can help these tutorials succeed by doing one of these:
Thanks!
Last Week’s Daily Coding Tips
Make The New Color Gradient Easier To Use By Conforming To View
Using CustomReflectable To Debug a SwiftUI View Whenever It Refreshes
Use a TextField To Create a Custom NavigationPath For The New NavigationStack
Store NavigateStack State Using An Enum With Associated Types
Snap a Sheet To Multiple Heights Like In Apple Maps With Presentation Detents