Open the starter project for this lesson and build and run the app. Tap the Flight Timeline button to bring up the timeline view. Right now, it shows a scrollable list of flight names and destinations.
Simple flight list view
In this lesson, you’ll start with this simple timeline view and then adapt it to a more reusable view that looks like this:
An improved and reusable flight list view
When building a complex view, you’ll find that starting with something simple and adding on will go faster than trying to do everything at once. First, you’ll work on the cards.
Inside the Timeline folder, create a new SwiftUI view named DepartureTimeView.swift and change the view and preview to:
struct DepartureTimeView: View {
var flight: FlightInformation
var body: some View {
VStack {
if flight.direction == .arrival {
Text(flight.otherAirport)
}
Text(flight.departureTime, style: .time)
}
}
}
#Preview {
DepartureTimeView(flight: FlightData.generateTestFlight(date: Date()))
}
This view displays the departure time for the flight, with the airport’s name above the departure time. Now, add a new SwiftUI view named ArrivalTimeView.swift in the same group and change it to:
struct ArrivalTimeView: View {
var flight: FlightInformation
var body: some View {
VStack {
if flight.direction == .departure {
Text(flight.otherAirport)
}
Text(flight.arrivalTime, style: .time)
}
}
}
#Preview {
ArrivalTimeView(flight: FlightData.generateTestFlight(date: Date()))
}
Now, return to FlightCardView.swift and add the following code inside the VStack after the HStack containing the flight’s statusBoardName:
This will show the two new views on the timeline and add some padding to the bottom of each row. Run the app, view the Flight Timeline, and you’ll see your changes.
Simple flight cards
In the next segment, you’ll continue to improve the flight timeline by adding a view that show’s each flight’s progress.
See forum comments
This content was released on Mar 12 2025. The official support period is 6-months
from this date.
Learn to build a reusable view that displays other views.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.