SwiftUI Cookbook
eBook - ePub

SwiftUI Cookbook

A guide to solving the most common problems and learning best practices while building SwiftUI apps, 2nd Edition

  1. 616 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

SwiftUI Cookbook

A guide to solving the most common problems and learning best practices while building SwiftUI apps, 2nd Edition

About this book

Unleash the power of declarative programming in SwiftUI by building cross-platform Apple apps for iOS 15, macOS, and watchOS using Swift 5.5, Xcode 13, and SwiftUI 3

Key Features

  • Apply the declarative programming paradigm to build cross-platform UIs for Apple devices
  • Learn to integrate UIkit, Core Data, Firebase, and Sign in with Apple with SwiftUI
  • Adopt the new SwiftUI 3.0 features to build visually appealing UIs speedily

Book Description

SwiftUI provides an innovative and simple way to build beautiful user interfaces (UIs) for all Apple platforms, from iOS and macOS through to watchOS and tvOS, using the Swift programming language. In this recipe-based cookbook, you'll cover the foundations of SwiftUI as well as the new SwiftUI 3 features introduced in iOS 15 and explore a range of essential techniques and concepts that will help you through the development process.

The cookbook begins by explaining how to use basic SwiftUI components. Once you've learned the core concepts of UI development, such as Views, Controls, Lists, and ScrollViews, using practical implementations in Swift, you'll advance to adding useful features to SwiftUI using drawings, built-in shapes, animations, and transitions. You'll understand how to integrate SwiftUI with exciting new components in the Apple development ecosystem, such as Combine for managing events and Core Data for managing app data. Finally, you'll write iOS, macOS, and watchOS apps by sharing the same SwiftUI codebase.

By the end of this SwiftUI book, you'll have discovered a range of simple, direct solutions to common problems encountered when building SwiftUI apps.

What you will learn

  • Explore various layout presentations in SwiftUI such as HStack, VStack, LazyHStack, and LazyVGrid
  • Create widgets to quickly display relevant content at glance
  • Get up to speed with drawings in SwiftUI using built-in shapes, custom paths, and polygons
  • Discover modern animation and transition techniques in SwiftUI
  • Add user authentication using Firebase and Sign in with Apple
  • Manage concurrency with Combine and async/await in SwiftUI
  • Solve the most common SwiftUI problems, such as integrating a MapKit map, unit testing, snapshot testing, and previewing layouts

Who this book is for

This book is for mobile developers who want to learn SwiftUI as well as experienced iOS developers transitioning from UIkit to SwiftUI. The book assumes knowledge of the Swift programming language. Knowledge of object-oriented design and data structures will be useful but not necessary. You'll also find this book to be a helpful resource if you're looking for reference material regarding the implementation of various features in SwiftUI.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access SwiftUI Cookbook by Giordano Scalzo,Edgar Nzokwe in PDF and/or ePUB format, as well as other popular books in Informatica & Hardware. We have over one million books available in our catalogue for you to explore.

Information

Year
2021
eBook ISBN
9781803240435
Edition
2
Subtopic
Hardware

Chapter 1: Using the Basic SwiftUI Views and Controls

SwiftUI was launched during Apple's Worldwide Developer Conference (WWDC) in June 2019. Since then, its popularity has kept increasing as it has been adopted more into the Apple developer community. Apple also releases updates every year, adding new and exciting capabilities to SwiftUI.
SwiftUI ditches UIKit concepts such as Auto Layout for an easier-to-use declarative programming model. It allows the fast and easy creation of applications that work across Apple platforms (iOS, iPadOS, and macOS).
Are you still wondering whether you should start learning SwiftUI? Here are a few reasons to convince you:
  • SwiftUI apps can work alongside UIKit apps: You can slowly convert your app's user interface (UI) to SwiftUI, one screen at a time.
  • Industry adoption: SwiftUI adoption among most companies will take time. Getting a head start and learning SwiftUI now improves your future marketability. SwiftUI today is like the early days of Objective-C versus Swift, where most companies still used Objective-C; now, almost everyone has switched to Swift.
  • Low learning curve: SwiftUI offers a low learning curve for people who have used declarative programming before. It is also a great way to start learning declarative programming for those with little-to-no experience.
  • Live previews increase speed: SwiftUI live previews provide an instant preview of your UI. You can quickly prototype apps and make any changes required by clients. This greatly improves the speed of UI development.
This book is designed to be your SwiftUI reference material. Each project focuses on a single concept so that you can understand each concept thoroughly, and then combine multiple concepts to build amazing applications.
In this chapter, we will learn about views and controls, SwiftUI's visual building blocks for app interfaces. The following recipes will be covered:
  • Laying out components
  • Dealing with text
  • Using images
  • Adding buttons and navigating with them
  • Beyond buttons – using advanced pickers
  • Applying groups of styles using ViewModifier
  • Separating presentation from content with ViewBuilder
  • Simple graphics using San Francisco Symbols (SF Symbols)
  • Integrating UIKit into SwiftUI—the best of both worlds
  • Adding SwiftUI to an existing app
  • Exploring more views and controls (iOS 14+)

Technical requirements

The code in this chapter is based on Xcode 13.0. You can download and install Xcode from the App Store.
All the code examples for this chapter can be found on GitHub at https://github.com/PacktPublishing/SwiftUI-Cookbook-2nd-Edition/tree/main/Chapter01-Using-the-basic-SwiftUI-Views-and-Controls.

Laying out components

SwiftUI uses three basic layout components, VStack, HStack, and ZStack. Use the VStack view to arrange components in a vertical axis, HStack to arrange components in a ...

Table of contents

  1. SwiftUI Cookbook
  2. Second Edition
  3. Contributors
  4. About the authors
  5. About the reviewers
  6. Preface
  7. Chapter 1: Using the Basic SwiftUI Views and Controls
  8. Chapter 2: Going Beyond the Single Component with Lists and Scroll Views
  9. Chapter 3: Exploring Advanced Components
  10. Chapter 4: Viewing while Building with SwiftUI Preview
  11. Chapter 5: Creating New Components and Grouping Views with Container Views
  12. Chapter 6: Presenting Extra Information to the User
  13. Chapter 7: Drawing with SwiftUI
  14. Chapter 8: Animating with SwiftUI
  15. Chapter 9: Driving SwiftUI with Data
  16. Chapter 10: Driving SwiftUI with Combine
  17. Chapter 11: SwiftUI Concurrency with async await
  18. Chapter 12: Handling Authentication and Firebase with SwiftUI
  19. Chapter 13: Handling Core Data in SwiftUI
  20. Chapter 14: Creating Cross-Platform Apps with SwiftUI
  21. Chapter 15: SwiftUI Tips and Tricks
  22. Other Books You May Enjoy