Chapter 7: History View Issues

I’m not sure but I suspect the following problems may be a result of changes in Xcode 13, 13.1 specifically.

The canvas preview stalls out for me and fails with more than 1000 random history items, may be my iMac but I have a 4.2 GHz Quad-Core Intel Core i7 with 40GB of ram.

The header doesn’t pin properly and Xcode doesn’t complain about an error when I make the changes to do it. It just always scrolls with the stack.

var body: some View {
      LazyVStack(spacing: 0, pinnedViews: [.sectionHeaders]) {
          ScrollView {
              Section(header: header) {
                  ForEach(history, id: \.self) { element in
                      getElement(element)
                  }
              }
          }
      }
  }

hi Vic! on p. 212 of the pdf, you embed the LazyVStack in the ScrollView:

ScrollView {
  LazyVStack {
    ForEach(history, id: \.self) { element in
      getElement(element)
    }
  }
}

then you continue working with the LazyVStack.

Hi Vic, it’s how @Audrey said, the scroll view should contain the stack and not the opposite.
However when I try to do as you did, all that I get is that the view doesn’t scroll.

Anyway, does putting scroll and stack in the right order solve your problem?

Thanks guys, Doing a real :man_facepalming:t2: here. That was in fact my issue. Solved the header issue and I was able to bump up the number of history items without Xcode stalling as well.

Sometimes you just stare at something too long and overlook the obvious thing that should be smacking you in the face. :joy:

2 Likes

Something similar happened to me a couple of steps before when we are asked to preview without the scrollview. I get an error from the canvas that it took more than 5 seconds. Once I enclosed the LazyVStack in the ScrollView, it immediately renders.

var body: some View {
          LazyVStack{
              ForEach(self.history, id:\.self) { element in
                  getElement(element)
              }
        }
  }