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.

As you dive in, there are a few things to take note of:

  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, 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.” 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. This will likely make a bit more sense after you dive in.
  3. The screen captures may be a bit hard to read without zooming in, but they are quite helpful.
  4. If you find yourself hitting a wall, you can always download the finished file to see what the code looks like. However, I would 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!

Read Chapter 5: Understanding ScrollView and Building a Carousel UI in Mastering SwiftUI