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
$15.99 per month
Book Sep 2023 268 pages 1st Edition
eBook
$27.99 $18.99
Print
$34.99
Subscription
$15.99 Monthly
eBook
$27.99 $18.99
Print
$34.99
Subscription
$15.99 Monthly

What do you get with a Packt Subscription?

Free for first 7 days. $15.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 a Packt Subscription?

Free for first 7 days. $15.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.