Understanding ScrollView and Building a Carousel UI

This chapter draws on everything you learned how to do (and more) in the previous three, and leads you through the process of building a vertical (and later horizontal) image and text carousel.

I went through this lesson very thoroughly a while back and took some notes that may be useful.

  1. The lesson asks you to create a new (and separate) CardView.swift file, do a lot of stuff with it,  and then leads you through the process of ‘refactoring’ the code of the CardView Struct (page 118) , but doesn’t ever clearly explain why you refactor it. As it turns out, you will reuse the CardView struct multiple times with ContentView.swift once it is fully created.
  2. As part of the restructuring, you are asked to change the code of the bottom struct “CardView_Previews: PreviewProvider.”  This part confused me the first time I did the exercise but I have since become enlightened. Each time you create a new SwiftUI view as you do in this lesson, the view comes with a preview component that displays whatever you add to the main struct. In this case, because you added variables to the main struct and inserted them in place of actual content, whenever you call the cardview struct, you have to create values for those variable. In the PreviewProvider you call the struct in order to preview it, so you have to add values for those variables. 
  3. The screen captures are hard to read without zooming in, but are quite helpful.
  4. You can always download the finished file if you get really frustrated but give the lesson your best shot before you resort to that ‘final solution’ because you are going to have to create something quite similar for your homework assignment and won’t have anything to download for that challenge!