Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Elevate SwiftUI Skills by Building Projects
Elevate SwiftUI Skills by Building Projects

Elevate SwiftUI Skills by Building Projects: Build four modern applications using Swift, Xcode 14, and SwiftUI for iPhone, iPad, Mac, and Apple Watch

By Frahaan Hussain
Can$35.99 Can$24.99
Book Sep 2023 268 pages 1st Edition
eBook
Can$35.99 Can$24.99
Print
Can$44.99
Subscription
Free Trial
eBook
Can$35.99 Can$24.99
Print
Can$44.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon AI Assistant (beta) to help accelerate your learning
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now
Table of content icon View table of contents Preview book icon Preview Book

Elevate SwiftUI Skills by Building Projects

Swift and SwiftUI Recap

Firstly, I would like to thank you for reading my book, be it bought or borrowed, or whether you’re having a sneak peek in the Amazon preview, I thank you.

This chapter will recap Swift and SwiftUI. We will first cover the coding standards used throughout the book for our upcoming projects and the history of Swift and SwiftUI. Then, we will take a look at the requirements for going through the projects in this book. Coding standards can be very polarizing for programmers, but they really shouldn’t be. If there are any you disagree with, feel free to tweet me at @SonarSystems and let me know why. But don’t let that detract from the book and what you can get from it.

Afterward, we will look at some specific SwiftUI code examples along with previews to close off the recap. We will look at how we can use views and controls; these are the visual building blocks of your application’s user interface. We will use them throughout the...

Technical requirements and standards

This book requires you to download Xcode version 14 or above from Apple’s App Store.

To install Xcode, just search for Xcode in the App Store and select and download the latest version. Open Xcode and follow any additional installation instructions. Once Xcode has opened and launched, you’re ready to go.

Version 14 of Xcode has the following features/requirements:

  • Includes SDKs for iOS 16, iPadOS 16, macOS 12.3, tvOS 16, and watchOS 9.
  • Supports on-device debugging in iOS 11 or later, tvOS 11 or later, and watchOS 4 or later.
  • Requires a Mac running macOS Monterey 12.5 or later.

Download the sample code from the following GitHub link:

https://github.com/PacktPublishing/Elevate-SwiftUI-Skills-by-Building-Projects

Here are the hardware requirements:

  • You need an Intel or Apple Silicon Mac
  • 4GB RAM or more

Here are the software requirements:

  • macOS 11.3 (Big Sur or later)
  • Xcode...

Standards used

In this section, we will look at the coding standards that are used throughout this book. It is important to have consistent standards and know what the standards are.

Why do we need coding standards?

It is important to write good code and good code isn’t just code that runs well but code that is easily maintainable and readable. Good code is an art form.

In the following sections, we will go through a set of standards that are used in the Swift programming language and these will be used throughout this book. If you do not fully agree with the standards, that is fine, but I felt it important to list the standards used in case you come across something you have never seen before, such as Yoda conditions – do any of you use them? If so, tweet me at @SonarSystems.

Indentation

You should always indent your code to be aligned with other code in the same hierarchy level. Use real tabs instead of spaces for indenting code. You can see this in the...

What is Swift?

In this section, we will cover what Swift is, its history, and how it works on a macro level. If you are an expert and just want to read about SwiftUI, feel free to skip this section.

Swift is a programming language created by Apple and the open source community. It is a general-purpose, compiled, and multi-paradigm programming language. It was released in 2014 as a replacement for Apple’s previous language, Objective-C. Due to the fact that Objective-C had remained virtually the same since the early 1980s, it was missing many features that modern languages have. Hence, the creation of Swift began; it has taken the Apple developer ecosystem by storm and is a hugely popular programming language. It is demanded by companies all over the world with excellent remuneration offered to those that know how to leverage its immense features. According to the PYPL index seen in the following figure, Swift is in the top 10 most popular languages, making it a must-have...

What is SwiftUI?

In this section, we will cover what SwiftUI is and the features provided that we will leverage throughout this book to create our projects. If you feel comfortable with SwiftUI and just want to see projects, then feel free to skip the remainder of this chapter.

SwiftUI is a user interface framework built on top of the Swift programming language. It provides many components for creating your app’s user interface; the following is a macro list of these components:

  • Views and controls
  • Shapes
  • Layout containers
  • Collection containers
  • Presentation containers

In addition to the components in the preceding list, SwiftUI provides us with event handlers, allowing our apps to react to taps, gestures, and all other types of input they may receive from the user. The framework provides tools to manage the flow of data from the models to the views and controls that the end user interacts with.

Now we will look at the different core features...

Understanding and implementing views

In this section, we will look at views and how we can implement them in SwiftUI. We will also take a look at combining these views.

Views are the fundamental building blocks of an application’s user interface. A view object renders content within its rectangle bounds and handles any interactions with that content.

In the following sections, we will show the source code and examples for each type of view. If you would like further information, visit Apple’s documentation at https://developer.apple.com/documentation/uikit/views_and_controls.

What are text views?

It is very common to need to display text in our app, and we do this by using a text view, which draws a string. By default, it has a font assigned to it that is best for the platform it is being displayed on; however, you can change the font using the font(_:) view modifier.

The following snippet shows the code used to implement a text view:

var body: some...

Understanding and implementing layouts

This section will cover how we can arrange our views using layouts for a more dynamic user experience.

SwiftUI layouts allow us as developers to arrange views in your app’s interface using the layout tools provided. Layouts tell SwiftUI how to place a set of views, and how much space it needs to do so to provide the desired layout.

Layouts can be but are not limited to any of the following:

  • Lazy stacks
  • Spacers:
    • ScrollViewReader
  • Grids:
    • PinnedScrollableViews

In the following sections, we will show you the source code and examples for each type of layout.

Note

If you would like further information, visit Apple’s documentation: https://developer.apple.com/documentation/uikit/view_layout.

What are lazy stacks?

Lazy stacks are views that arrange their children in a line that expands vertically, creating items only as needed.

SwiftUI provides two different types of lazy stacks, LazyVStack and LazyHStack...

Device Previews

One of the many hurdles we will overcome is the differences between the four main Apple product categories. These categories are as follows:

  • Mac – iMac, Mac Pro, MacBook, anything that runs macOS, even Hackintosh
  • iPad – Mini, regular, Air, Pro, all of them
  • iPhone – Mini, Pro, Pro Max, all iPhones
  • Apple Watch – small, big, old, or new

The obvious thing you will notice is that they get smaller and smaller. They naturally have different purposes; an Apple Watch won’t replace a Mac and vice versa. That is why the next eight chapters are grouped into pairs, one for each product category. We will uncover the design decisions and restrictions we have when creating our applications. Let’s take a look at the settings in each product category:

Mac

Figure 1.13 – Mac settings

Figure 1.13 – Mac settings

iPad

Figure 1.14 – iPad settings

Figure 1.14 – iPad settings

iPhone

Figure 1.15 – iPhone settings ...

Summary

In this chapter, we covered the history of Swift and SwiftUI, the features provided to us on a macro level, and how Swift and SwiftUI work on a technical level. Then, we looked at the difference between Swift and SwiftUI and what features are offered, along with code samples for you to take away and use in your own projects. After that, we took a look at the requirements necessary for developing applications with Swift and SwiftUI. Then, we took a look at the coding standards that are used throughout this book, providing a reference point for any coding style that is unfamiliar to your own. Then, we looked at the views and controls provided by SwiftUI for creating our own user experiences, including custom views by combining the fundamentals. Finally, we took a look at how we can organize these views using layouts and checked the device previews too.

In our next chapter, we’ll take a look at designing our first project, the tax calculator app that we will create.

...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn how to use the latest SwiftUI features such as UIkit
  • Develop UIs for all categories of Apple devices, from the Apple Watch to the iPad
  • Enhance your applications further with advanced SwiftUI features
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

Elevate SwiftUI Skills by Building Projects helps you harness the cutting-edge potential of SwiftUI and its innovative and user-friendly approach to crafting user interfaces for Apple platforms with the power of Swift. This book will enhance your UI programming skills with SwiftUI through a project-based methodology, guiding you to create four real-world projects. Starting with a quick recap of Swift and SwiftUI, you’ll gradually develop projects tailored for iPhone, iPad, macOS, and watchOS using Swift and Xcode. You’ll experience SwiftUI’s versatility in action as you build a tax calculator for iPhone and a photo gallery for the iPad, which uses a larger display to enhance the viewing experience. You’ll also create an app store for Mac and, finally, get to grips with the power of SwiftUI for smaller devices such as the Apple Watch by designing a Fitness Companion app. By the end of this book, you'll have built fully functional projects across multiple platforms and gained the expertise needed to excel as a professional SwiftUI developer.

What you will learn

Start with a quick recap of UI essentials in Swift and Swift basics Discover how UI elements are integrated into apps Understand how SwiftUI builds on top of the pre-existing Swift programming language Familiarize yourself with the latest Xcode version to create SwiftUI apps Develop a wide variety of applications that can be used as cornerstones Design and code for watchOS, iOS, macOS, and iPadOS in SwiftUI through explicit projects

Product Details

Country selected

Publication date : Sep 8, 2023
Length 268 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781803242071
Vendor :
Apple
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon AI Assistant (beta) to help accelerate your learning
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Sep 8, 2023
Length 268 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781803242071
Vendor :
Apple
Category :
Languages :
Tools :

Table of Contents

12 Chapters
Preface Chevron down icon Chevron up icon
1. Chapter 1: Swift and SwiftUI Recap Chevron down icon Chevron up icon
2. Chapter 2: iPhone Project – Tax Calculator Design Chevron down icon Chevron up icon
3. Chapter 3: iPhone Project – Tax Calculator Functionality Chevron down icon Chevron up icon
4. Chapter 4: iPad Project – Photo Gallery Overview Chevron down icon Chevron up icon
5. Chapter 5: iPad Project – Photo Gallery Enhanced View Chevron down icon Chevron up icon
6. Chapter 6: Mac Project – App Store Bars Chevron down icon Chevron up icon
7. Chapter 7: Mac Project – App Store Body Chevron down icon Chevron up icon
8. Chapter 8: Watch Project – Fitness Companion Design Chevron down icon Chevron up icon
9. Chapter 9: Watch Project – Fitness Companion UI Chevron down icon Chevron up icon
10. Index Chevron down icon Chevron up icon
11. Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Top Reviews
No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.