SwiftUI Cookbook: A best practice guide to solving the most common problems in using SwiftUI, 2nd Edition
- Length: 621 pages
- Edition: 2
- Language: English
- Publisher: Packt Publishing
- Publication Date: 2021-11-09
- ISBN-10: 1803234458
- ISBN-13: 9781803234458
- Sales Rank: #511077 (See Top 100 Books)
Find practical, logical, and efficient recipes for building cross-platform apps for iOS 15, macOS, and watchOS using Swift 5.5, Xcode 13, and SwiftUI 3.0
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, right 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.
Table of Contents
- Using the Basic SwiftUI Views and Controls
- Going Beyond the Single Component with Lists and Scroll Views
- Exploring Advanced Components
- Viewing while Building with SwiftUI Preview
- Creating New Components and Grouping Views with Container Views
- Presenting Extra Information to the User
- Drawing with SwiftUI
- Animating with SwiftUI
- Driving SwiftUI with Data
- Driving SwiftUI with Combine
- SwiftUI Concurrency with async await
- Handling Authentication and Firebase with SwiftUI
- Handling Core Data in SwiftUI
- Creating Cross-Platform apps with SwiftUI
- SwiftUI Tips and Tricks
SwiftUI Cookbook Second Edition Contributors About the authors About the reviewers Preface Who this book is for What this book covers To get the most out of this book Download the example code files Download the color images Conventions used Sections Getting ready How to do it… How it works… There's more… See also Get in touch Chapter 1: Using the Basic SwiftUI Views and Controls Technical requirements Laying out components Getting ready How to do it… How it works… There's more… Dealing with text Getting ready How to do it… How it works… There's more… See also Using images Getting ready How to do it… How it works… See also Adding buttons and navigating with them Getting ready How to do it… How it works… See also Beyond buttons – using advanced pickers Getting ready How to do it… How it works… Applying groups of styles using ViewModifier Getting ready How to do it… How it works… See also Separating presentation from content with ViewBuilder Getting ready How to do it… How it works… See also Simple graphics using SF Symbols Getting ready How to do it… How it works… See also Integrating UIKit into SwiftUI – the best of both worlds Getting ready How to do it… How it works… See also Adding SwiftUI to an existing app Getting ready How to do it… How it works… Exploring more views and controls (iOS 14+) Getting ready How to do it… How it works… Chapter 2: Going Beyond the Single Component with Lists and Scroll Views Technical requirements Using scroll views Getting ready How to do it… How it works… See also Creating a list of static items Getting ready How to do it… How it works… Using custom rows in a list Getting ready How to do it… How it works… Adding rows to a list Getting ready How to do it… How it works… Deleting rows from a list Getting ready How to do it… How it works… There's more… Creating an editable List view Getting ready How to do it… How it works… There's more… Moving the rows in a List view Getting ready How to do it… How it works… Adding sections to a list Getting ready How to do it… How it works… Creating editable Collections Getting ready How to do it… How it works… Using Searchable lists Getting ready How to do it… How it works… There's more… Chapter 3: Exploring Advanced Components Technical requirements Using LazyHStack and LazyVStack Getting ready How to do it… How it works… There's more… Displaying tabular content with LazyHGrid and LazyVGrid Getting ready How to do it… How it works… Scrolling programmatically with ScrollViewReader Getting ready How to do it… How it works… Displaying hierarchical content in expanding lists Getting ready How to do it… How it works… There's more… Using disclosure groups to hide and show content Getting ready How to do it… How it works… Creating SwiftUI widgets Getting ready How to do it… How it works… See also Chapter 4: Viewing while Building with SwiftUI Preview Technical requirements Previewing a layout in dark mode Getting ready How to do it How it works Previewing a layout at different dynamic type sizes Getting ready How to do it How it works See also Previewing a layout in a NavigationView Getting ready How to do it How it works Previewing a layout on different devices Getting ready How to do it How it works Using previews in UIKit Getting ready How to do it How it works See also Using mock data for previews Getting ready How to do it How it works There's more Chapter 5: Creating New Components and Grouping Views with Container Views Technical requirements Showing and hiding sections in forms Getting ready How to do it… How it works… There's more… See also Disabling and enabling items in forms Getting ready How to do it… How it works… Filling out forms easily using Focus and Submit Getting ready How to do it… How it works… There's more… See also Navigating between multiple views with TabView Getting ready How to do it… How it works… There's more… See also Using gestures with TabView Getting ready How to do it… How it works… Chapter 6: Presenting Extra Information to the User Technical requirements Presenting alerts Getting ready How to do it How it works See also Adding actions to alert buttons Getting ready How to do it How it works Presenting confirmation dialogs Getting ready How to do it How it works See also Presenting new views using sheets Getting ready How to do it How it works See also Creating context menus Getting ready How to do it How it works See also Displaying popovers Getting ready How to do it How it works See also Chapter 7: Drawing with SwiftUI Technical requirements Using SwiftUI's built-in shapes Getting ready How to do it… How it works… Drawing a custom shape Getting ready How to do it… How it works… Drawing a curved custom shape Getting ready How to do it… How it works… Drawing using the Canvas API Getting ready How to do it… How it works… There's more… Implementing a progress ring Getting ready How to do it… How it works… Implementing a Tic-Tac-Toe game in SwiftUI Getting ready How to do it… How it works… There's more… Rendering a gradient view in SwiftUI Getting ready How to do it… How it works… Building a bar chart Getting ready How to do it… How it works… There's more… Building a pie chart Getting ready How to do it… How it works Chapter 8: Animating with SwiftUI Technical requirements Creating basic animations Getting ready How to do it… How it works… There's more… See also Transforming shapes Getting ready How to do it… How it works… Creating a banner with a spring animation Getting ready How to do it… How it works… Applying a delay to a view modifier animation to create a sequence of animations Getting ready How to do it… How it works… Applying a delay to a withAnimation function to create a sequence of animations Getting ready How to do it… How it works… Applying multiple animations to a view Getting ready How to do it… How it works… Creating custom view transitions Getting ready How to do it… How it works… Creating a hero view transition with .matchedGeometryEffect Getting ready How to do it… How it works… Lottie animations in SwiftUI Getting ready How to do it… How it works… Implementing a stretchable header in SwiftUI Getting ready How to do it… How it works… Creating floating hearts in SwiftUI Getting ready How to do it… How it works… See also Implementing a swipeable stack of cards in SwiftUI Getting ready How to do it… How it works… Chapter 9: Driving SwiftUI with Data Technical requirements Using @State to drive a View's behavior Getting ready How to do it… How it works… See also Using @Binding to pass a state variable to child Views Getting ready How to do it… How it works… Implementing a CoreLocation wrapper as @ObservedObject Getting ready How to do it… How it works… Using @StateObject to preserve the model's life cycle Getting ready How to do it… How it works... Sharing state objects with multiple Views using @EnvironmentObject Getting ready How to do it… How it works… See also Chapter 10: Driving SwiftUI with Combine Technical requirements Introducing Combine in a SwiftUI project Getting ready How to do it… How it works… See also Managing the memory in Combine to build a timer app Getting ready How to do it… How it works… See also Validating a form using Combine Getting ready How to do it… How it works… There's more… Fetching remote data using Combine and visualizing it in SwiftUI Getting ready How to do it… How it works… There's more… Debugging an app based on Combine Getting ready How to do it… How it works… There's more… Unit testing an app based on Combine Getting ready How to do it… How it works… Chapter 11: SwiftUI Concurrency with async await Technical requirements Integrating SwiftUI and an async function Getting ready How to do it… How it works… Fetching remote data in SwiftUI Getting ready How to do it… How it works… Pulling and refreshing data asynchronously in SwiftUI Getting ready How to do it… How it works… Converting a completion block function to async await Getting ready How to do it… How it works… See also Implementing infinite scrolling with async await Getting ready How to do it… How it works… See also Chapter 12: Handling Authentication and Firebase with SwiftUI Technical requirements Implementing Sign in with Apple in a SwiftUI app Getting ready How to do it… How it works… Integrating Firebase into a SwiftUI project Getting ready How to do it… How it works… There's more… Using Firebase to sign in using Google Getting ready How to do it… How it works… Implementing a distributed Notes app with Firebase and SwiftUI Getting ready How to do it… How it works… There's more… Chapter 13: Handling Core Data in SwiftUI Technical requirements Integrating Core Data with SwiftUI Getting ready How to do it… How it works… There's more… Showing Core Data objects with @FetchRequest Getting ready How to do it… How it works… Adding Core Data objects from a SwiftUI view Getting ready How to do it… How it works… Filtering Core Data requests using a predicate Getting ready How to do it… How it works… Deleting Core Data objects from a SwiftUI view Getting ready How to do it… How it works… Presenting data in a sectioned list with @SectionedFetchRequest Getting ready How to do it… How it works… Chapter 14: Creating Cross-Platform Apps with SwiftUI Technical requirements Creating an iOS app in SwiftUI Getting ready How to do it… How it works… Creating the macOS version of the iOS app Getting ready How to do it… How it works… Creating the watchOS version of the iOS app Getting ready How to do it… How it works… Chapter 15: SwiftUI Tips and Tricks Technical requirements Snapshot testing SwiftUI views Getting ready How to do it… How it works… Unit testing SwiftUI with ViewInspector Getting ready How to do it… How it works… See also Showing a PDF in SwiftUI Getting ready How to do it… How it works… There's more… Implementing SwiftUI views using Playground Getting ready How to do it… How it works… Using custom fonts in SwiftUI Getting ready How to do it… How it works… Implementing a Markdown editor with Preview Getting ready How to do it… How it works… Hi! Why subscribe? Other Books You May Enjoy Packt is searching for authors like you
Donate to keep this site alive
How to download source code?
1. Go to: https://github.com/PacktPublishing
2. In the Find a repository… box, search the book title: SwiftUI Cookbook: A best practice guide to solving the most common problems in using SwiftUI, 2nd Edition
, sometime you may not get the results, please search the main title.
3. Click the book title in the search results.
3. Click Code to download.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.