Chapter 6
Understanding List and ForEach
That's been one of my mantras - Focus and Simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains.
- Steve Jobs
Now that you have a basic understanding of prototyping and our demo app, we'll work on something more interesting and build a simple app using the List
view in this chapter. Once you master the technique and list views, we'll start to build the Food Pin app.
First of all, what exactly is a list view in an iPhone app? If you have worked with UIKit before, a list view in SwiftUI is exactly the same as a table view in UIKit. A list view is one of the most common UI elements in iOS apps. Most apps (except games), in some ways, make use of table view to display content. The best example is the built-in Phone app. Your contacts are displayed in a table view. Another example is the Mail app. It uses a table view to display your mail boxes and emails. Not only designed for listing textual data, table view allows you to present the data in the form of images. The TED, Google+ and Airbnb are also good examples. Figure 6-1 displays a few more sample list-based apps. Though they look different, all the app UIs can be built using list views.
What we are going to do in this chapter is create a very simple list view and learn how to populate data (images and text) into it. If you've built a table view with UIKit before, you know it'll take you a bit of work to implement a simple table view. SwiftUI simplifies this whole process. With just a few lines of code, you will be able to list data in table form. Even if you need to customize the layout of the rows, it only requires minimal effort.
Feeling confused? No worries. You'll understand what I mean in a while.
To access the full version of the book, please get the full copy here. You will also be able to access the full source code of the project.