SALE ENDS TODAY: Save 50% on all Swift books and bundles! >>

SwiftUI tutorial: Building a complete project

Paul Hudson    @twostraws   

Fully updated for Xcode 11.2

This is a complete, free SwiftUI tutorial designed to take you through lots of its functionality in a single project. It’s aimed at people who have existing programming experience with UIKit, but most things are explained in detail so newcomers ought to be able to follow along.

The project we’ll be making is called iDine, and is a restaurant app that lists items in a menu and helps folks place orders. I’ve designed the project specifically so that it covers as many different techniques as possible to give you a good grounding in how things work in SwiftUI. Of course, we’re also building a real project at the same time – it’s going to be busy!

Advance warning: It’s really easy to make mistakes in SwiftUI, and right now the errors generated by the compiler are less than helpful – you might get a complaint about line 8 when really the problem is on line 23, or when the error is on the right line it’s sometimes something obscure. These problems are, for now at least, perfectly normal.

To get started, please create a new iOS project in Xcode called “iDine”, choosing the Single View App template and choosing SwiftUI for the User Inteface.

There are quite a few assets provided for this project that you need to copy in before you start. These are all in the assets for this project, which you can download here: https://www.hackingwithswift.com/samples/idine.zip.

Please copy them into your project like this:

  • Drag Helper.swift into your project navigator. This contains a helper extension that makes it easier to decode Codable data from a bundle. This is a pre-iOS 13 thing, so we won’t be covering it here.
  • You should also drag Order.swift and Menu.swift into the project navigator. These are custom types that store the data we’re using in the app.
  • And drag menu.json into your project navigator too – this describes all the menu items our restaurant offers, and will be decoded into instances of MenuSection and MenuItem.
  • Drag the contents of the Images directory into your asset catalog, so we have all the pictures we need.

OK, that’s it – we’re ready to go!

Tip: At the end of each chapter I’ve added a “Further reading” section that suggests links to other chapters in this book. You don’t need to read them in order to follow along; they are there to provide extra information and detail if you want to understand the bigger picture more thoroughly.

SPONSORED Instabug helps you identify and resolve severe crashes quickly. You can retrace in-app events and know exactly which line of code caused the crash along with environment details, network logs, repro steps, and the session profiler. Ask more questions or keep users up-to-date with in-app replies straight from your dashboard. Instabug takes data privacy seriously, so no one sees your data but you! See more detailed features comparison and try Instabug's crash reporting SDK for free.

Save 50% on all books and bundles

The biggest ever Hacking with Swift sale is now on, letting you save 50% on all books and bundles. Learn something new with Swift and enjoy great savings while the sale lasts!

Click here to save 50% in our Black Friday sale!

Similar solutions…

BUY OUR BOOKS
Buy Pro Swift Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift (Vapor Edition) Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Server-Side Swift (Kitura Edition) Buy Beyond Code

Was this page useful? Let us know!

Average rating: 4.3/5