SwiftUI Cookbook - Giordano Scalzo - E-Book

SwiftUI Cookbook E-Book

Giordano Scalzo

0,0
29,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

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.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 430

Veröffentlichungsjahr: 2021

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



SwiftUI Cookbook Second Edition

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

Giordano Scalzo

Edgar Nzokwe

BIRMINGHAM—MUMBAI

SwiftUI Cookbook

Second Edition

Copyright © 2021 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Group Product Manager: Rohit Rajkumar

Publishing Product Manager: Ashitosh Gupta

Senior Editor: Hayden Edwards

Content Development Editor: Rashi Dubey

Technical Editor: Joseph Aloocaran

Copy Editor: Safis Editing

Project Coordinator: Rashika Ba

Proofreader: Safis Editing

Indexer: Manju Arasan

Production Designer: Vijay Kamble

First published: October 2020

Second edition: October 2021

Production reference: 1291021

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80323-445-8

www.packt.com

We wrote this book standing on the shoulders of giants.

Thanks to Dave Verwer, Majid Jabrayilov, John Sundell, Gui Rambo, Gio Lodi, Antoine van der Lee, Donny Wals, Vincent Pradelles, Mark Moeykens, Paul Hudson, and all the fantastic Swift community for the support and knowledge. – Giordano Scalzo

To my childhood mentor, Mr. Tatuh N. Atem Formin, who introduced me to the amazing world of computing.– Edgar Nzokwe

Contributors

About the authors

Giordano Scalzo started his journey back in the days of ZX Spectrum. He has worked with Swift, Objective-C, C/C++, Java, .NET, Ruby, Python, and a ton of other languages that he has forgotten the names of. He is currently a tech lead consultant in London, where he leads mobile digital transformations through his company, Effective Code Ltd.

To my bright future, Mattia and Luca, for giving me lots of smiles and hugs when I needed them.

To my better half, Valentina, who lovingly supports me in everything I do: without you, none of this would have been possible.

Edgar Nzokwe is a software engineer with 6+ years of experience building web and mobile applications. His areas of expertise include SwiftUI, UIKit, Kotlin, Python, and a few JavaScript frameworks. Edgar is dedicated to advancing the knowledge base of SwiftUI because he believes it empowers developers to design and build dazzling cross-platform apps with minimal development time.

I want to thank my wife, Mabelle, for encouraging me along this journey.

Thanks to my kids, Neil and Zoe, for making me smile when the going got tough.

Finally, I want to give special thanks to my editors, Hayden Edwards and Rashi Dubey, as well as the rest of the Packt team who helped put this book together.

About the reviewers

Chris Barker is an iOS developer and principal software manager for Jaguar Land Rover, where he heads up the mobile app team.

Chris started his career developing .NET applications for online retailer dabs.com (now BT Shop) before he made his move into mobile app development with digital agency Openshadow (now MyStudioFactory Paris). There, he worked on mobile apps for clients such as Louis Vuitton and L'Oréal Paris.

He has since worked for online fashion retailer N Brown (JD Williams, SimplyBe, Jacamo) as an iOS tech lead.

Chris often attends and speaks at local iOS developer meetups and conferences such as NSManchester, Malaga Mobile, and CodeMobile.

Danny Bolella is an iOS developer lead at a major trading company. With over a decade of experience under his belt, he's worked on everything from full-stack web to mobile apps in a variety of industries, including financial, energy, and medical devices. He also enjoys writing articles and was the technical reviewer for SwiftUI Cookbook, First Edition.

Danny thanks his amazing wife and children, who give him the motivation and drive to always be better.

Marc Aupont is a first-generation American born to Haitian immigrant parents. After 12 years of working in fintech, he transitioned into mobile software development when Swift was announced in 2015. His passion for technology led him to move from Orlando, FL to NYC in 2017, where he started multiple meetups teaching programming. In addition to his work as a senior iOS engineer at Nike, Marc has been a champion for inclusion and diversity within developer communities for many years. Marc has worked to create opportunities for technical growth in the Swift community by organizing meetups for beginners, sharing his own experience and expertise through mentorship programs, working collaboratively with HBCU students on app development, and more. His hobbies include working on side projects involving electronics and hardware, serving as a music director at his local church, and going on weekend road trips to random destinations with his family.

Table of Contents

Preface

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