SwiftUI: Layout & Interfaces, Episode 7: Challenge: Grids with Pinned Views | raywenderlich.com

Create a colorful, vertically-scrolling grid-based layout, which resembles the “Search” view from Apple Music.

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/28684964-swiftui-layout-interfaces/lessons/7

I am curious as to why you did a LazyVGrid within a LazyVStack?

I just did a LazyVGrid at the top with ForEach for Genre and within that a ForEach for the Subgenre . It seems to have the same functionality but maybe I am missing something.

1 Like

I’m curious as well! But it’s been quite a while since I made this and I unfortunately don’t remember.

Here’s the better solution:

  columns: [.init(.adaptive(minimum: 150))],
  pinnedViews: .sectionHeaders
) {
  ForEach(Genre.list) { genre in
    Section(header: genre.header.id(genre)) {
      ForEach(genre.subgenres, content: \.view)
1 Like

That is pretty much what I did. I was worried there was some hidden reason that might bite me later :slight_smile:

SwiftUI makes me nervous in the same way Kotlin for Android does – makes lots of things easier but there is a lot of “magic” behind the scenes that you have little control over :slight_smile:

But I am forging ahead to learn enough to convert my existing UIKit apps…

1 Like