ENGLISH

Asynchronous Programming with SwiftUI and Combine: Functional Programming to Build UIs on Apple Platforms

Book information

Publisher
Apress
Year
2023
ISBN
9781484285718, 9781484285725
Language
english
Format
PDF
Filesize
6 MB (6569010 bytes)
Pages
\447
Time added
2023-01-16 23:37:39

Description

Develop UI-heavy applications more easily, faster, and error-free. Based on several enhancements to the Swift language, SwiftUI takes a declarative approach to building UIs. Instead of imperatively coding the UI, this book will show you how to describe how you want your UI to look. SwiftUI treats the UI as a function of its state, thereby making managing your app’s state a lot easier. Change the underlying data model to redraw all parts of the UI that are connected to that particular slice of data. Likewise, easily update the underlying data model from the UI elements your data model is connected to. Combine is Apple’s Functional Reactive Programming framework. It complements SwiftUI and other frameworks, such as the networking APIs, in a natural way. Using Combine, you can subscribe to events and describe data processing in a way that is free of side effects. This allows for an easier implementation of event-driven applications. Using SwiftUI and Combine build more error-free apps in a shorter amount of time, targeting all of Apple’s platforms (iOS, iPadOS, watchOS, macOS, tvOS) with little to no overhead. By the end of the book you will have a solid understanding for architecting and implementing UI-heavy apps in a declarative and functional reactive way using SwiftUI, Combine, and async/await.   You will: -       Build simple and gradually more complex UIs in SwiftUI -       Understand SwiftUI’s state management system -       Work with Combine and Swift’s new async/await APIs to access the network and access other asynchronous APIs -       Architect and structure modern applications on Apple platforms using SwiftUI, Combine, and async/await Table of Contents About the Author Foreword Preface Acknowledgments About This Book Part: 1 Chapter 1: SwiftUI: A New Beginning Why a New UI Framework? SwiftUI Principles Declarative vs. Imperative State Management Composition over Inheritance Everything Is a View—Except That It Isn’t UIs Are a Function of Their State A Quick Tour of SwiftUI Prerequisites Creating a New SwiftUI App Adding Some Interaction to Your App Using SwiftUI’s State Management to Keep UI and Model in Sync Exercises Summary Chapter 2: Getting Started with SwiftUI What We’re Going to Build Composing a View for Displaying a Book Build the View with Static Data Using the Preview to Make Sure Our View Works As Intended Displaying a List of Books Setting Up Data Binding Adjusting the Preview Canvas Making the Code Reusable Refactoring the Code Using Extract Subview Renaming ContentView Keep Complexity in Check Views and View Modifiers Exercises Tips and Tricks Summary Chapter 3: SwiftUI Building Blocks Views User Interface Views Text Input and Output Images Controls and Indicators Shapes Container Views Layout Behavior Hugging Expanding Views Are Just Descriptions of the UI View Modifiers Configuring Views Applying View Modifiers to Child Views Using View Modifiers to Register Action Handlers Summary Chapter 4: State Management Managing State in SwiftUI Binding Value Types Binding Objects ObservableObject @StateObject When to Use @ObservedObject When to Use @EnvironmentObject When to Use Summary Chapter 5: Displaying Data in Lists Getting Started with Lists in SwiftUI Using Other SwiftUI Views Inside List Rows Building Custom List Rows More Complex List Rows Dynamic Lists Displaying a List of Elements Using List Bindings to Allow Modifying List Items Asynchronously Fetching Data Pull-to-Refresh Searching Styling List Styles Headers and Footers List Cells Separators Actions Swipe-to-Delete Moving and Deleting Items Using EditMode Swipe Actions Basic Swipe Actions Specifying the Edge Swipe Actions and onDelete Adding More Swipe Actions Full Swipe Styling Your Swipe Actions Managing Focus in Lists How to Manage Focus in SwiftUI How to Manage Focus in Lists Handling the Enter Key What About MVVM? Eliminating Empty Elements Summary Chapter 6: Building Input Forms Building Simple Forms Showing Data in a Form Make It Editable Drill-Down Navigation Input Validation Using .onChange(of:) Using a View Model to Handle Form Validation Synchronizing a Local Source of Truth with the Global Source of Truth by Using @Binding and @ObservableObject Using Combine to Perform Form Validation Summary Part: 2 Chapter 7: Getting Started with Combine What Is Functional Reactive Programming? Publishers Subscribers Operators Composing Operators Combining Publishers Summary Chapter 8: Driving UI State with Combine Input Validation Using Combine The Sign-Up Form View The View Model Validating the Username Displaying Validation Messages Encapsulating Combine Pipelines in Computed Properties Validating the Password Putting It All Together Exercises Summary Chapter 9: Networking with Combine Fetching Data Using URLSession Using Combine to Fetch Data Destructuring Tuples Using Key Paths Mapping Data Fetching Data Using Combine, Simplified Connecting to the UI Handling Multithreading Optimizing Network Access Finding the Root Cause Using the share Operator to Share a Publisher Using debounce to Further Optimize the UX Using removeDuplicates to Avoid Sending the Same Request Twice Bringing It All Together Exercises Summary Chapter 10: Error Handling in Combine Error Handling Strategies Ignoring the Error Retrying (with Exponential Backoff) Showing an Error Message Replacing the Entire View with an Error View Showing an Inline Error Message Typical Error Conditions and How to Handle Them Implementing a Fallible Network API Calling the API and Handling Errors Handling Device/Network Offline Errors Handling Validation Errors Handling Response Parsing Errors Handling Internal Server Errors Summary Chapter 11: Implementing Custom Combine Operators What Is a Combine Operator? Implementing Custom Operators Implementing a Retry Operator with a Delay Conditionally Retrying Implementing a Retry Operator for Exponential Backoff Summary Chapter 12: Wrapping Existing APIs in Combine A Case Study Using Combine to Access Firestore Using View Models and Published Properties Using Combine to Wrap APIs Creating Your Own Publishers Using PassthroughSubject to Wrap Snapshot Listeners Using Future to Implement One-Time Fetching from Firestore Summary Chapter 13: Combine Schedulers and SwiftUI What Is a Scheduler Types of Schedulers Default Behavior Switching Schedulers Controlling Upstream Publishers Using subscribe(on:) Controlling Downstream Subscribers Using receive(on:) Other Operators That Influence Scheduling Performing Asynchronous Work Integrating with Other APIs URLSession Firebase Summary Part: 3 Chapter 14: Getting Started with async/await Synchronous Programming with Functions Asynchronous Programming with Closures Asynchronous Programming with async/await Defining and Calling Asynchronous Functions Calling Asynchronous Functions in Parallel Summary Chapter 15: Using async/await in SwiftUI Fetching Data Asynchronously Using URLSession Calling Asynchronous Code The Task View Modifier Calling Asynchronous Code When the User Taps a Button Using Pull-to-Refresh to Update Views Asynchronously Searchable Views and async/await Updating the UI from the Main Thread Summary Chapter 16: Bringing It All Together: SwiftUI, async/await, and Combine Fetching Data Using Combine Fetching Data Using async/await Is This the End of Combine? Connecting the UI… …to a Combine Pipeline …to an async/await Method Calling Asynchronous Code from Combine Summary Index

Similar books

Session C11: Ancient Cultural Landscapes in South Europe – their Ecological Setting and Evolution, Session C22: Gardeners from South America, Session S04: Agro-Pastoralism and Early Metallurgy Sessions, Session WS29: The Idea of Enclosure in Recent Iberian Prehistory, Session C88: Rhytmes et causalites des dynamiques de l'anthropisation en Europe entre 6500 ET 500 BC: Hypotheses socio-culturelles et/ou climatiques: Proceedings of the XV UISPP World Congress (Lisbon 4-9 September 2006) / Actes du XV Congrès Mondial (Lisbonne 4-9 Septembre 2006) Vol.36

Session C11: Ancient Cultural Landscapes in South Europe – their Ecological Setting and Evolution, Session C22: Gardeners from South America, Session S04: Agro-Pastoralism and Early Metallurgy Sessions, Session WS29: The Idea of Enclosure in Recent Iberian Prehistory, Session C88: Rhytmes et causalites des dynamiques de l'anthropisation en Europe entre 6500 ET 500 BC: Hypotheses socio-culturelles et/ou climatiques: Proceedings of the XV UISPP World Congress (Lisbon 4-9 September 2006) / Actes du XV Congrès Mondial (Lisbonne 4-9 Septembre 2006) Vol.36

2010 · PDF

THE BRITISH ARMY IN INDIA: ITS PRESERVATION BY AN APPROPRIATE CLOTHING, HOUSING, LOCATING, RECREATIVE EMPLOYMENT, AND HOPEFUL ENCOURAGEMENT OF THE TROOPS. with AN APPENDIX ON INDIA : THE CLIMATE OP ITS HILLS ; THE DEVELOPMENT OF ITS RESODRCBS, INDUSTRY, AND ARTS ; THE ADMINISTRATION OF JUSTICE ; THE BLACK ACT ; THE PROGRESS OF CHRISTIANITY ; THE TRAFFIC IN OPIUM ; THE VALUE OF INDIA ; PERMANENT CAUSES OF DISAFFECTION, AND OF THE RECENT REBELLION ; THE TRADITIONARY POLICY; MISGOVERNMENT BY NATIVE RULERS ; ANNEXATIONS OF THEIR TERRITORY, ETC.

THE BRITISH ARMY IN INDIA: ITS PRESERVATION BY AN APPROPRIATE CLOTHING, HOUSING, LOCATING, RECREATIVE EMPLOYMENT, AND HOPEFUL ENCOURAGEMENT OF THE TROOPS. with AN APPENDIX ON INDIA : THE CLIMATE OP ITS HILLS ; THE DEVELOPMENT OF ITS RESODRCBS, INDUSTRY, AND ARTS ; THE ADMINISTRATION OF JUSTICE ; THE BLACK ACT ; THE PROGRESS OF CHRISTIANITY ; THE TRAFFIC IN OPIUM ; THE VALUE OF INDIA ; PERMANENT CAUSES OF DISAFFECTION, AND OF THE RECENT REBELLION ; THE TRADITIONARY POLICY; MISGOVERNMENT BY NATIVE RULERS ; ANNEXATIONS OF THEIR TERRITORY, ETC.

1858 · PDF

Idries Shah 27 Books Collection : A Perfumed Scorpion, A Veiled Gazelle, Caravan of Dreams, Darkest England, Destination Mecca, Evenings with Idries Shah, Knowing How to Know, Learning How to Learn, Letters and Lectures of Idries Shah, Neglected aspects of Sufi study, Observations, Oriental Magic, Reflections, Seeker after Truth, Special Illumination, Special Problems in the study of Sufi ideas, Sufi thought and action, Tales of the Dervishes, The Dermis Probe, The Elephant in the Dark, The Englishman Handbook, Idries Shah Antology, The Magic Monastery, The natives are restless, wisdom of the Idiots PDF.

Idries Shah 27 Books Collection : A Perfumed Scorpion, A Veiled Gazelle, Caravan of Dreams, Darkest England, Destination Mecca, Evenings with Idries Shah, Knowing How to Know, Learning How to Learn, Letters and Lectures of Idries Shah, Neglected aspects of Sufi study, Observations, Oriental Magic, Reflections, Seeker after Truth, Special Illumination, Special Problems in the study of Sufi ideas, Sufi thought and action, Tales of the Dervishes, The Dermis Probe, The Elephant in the Dark, The Englishman Handbook, Idries Shah Antology, The Magic Monastery, The natives are restless, wisdom of the Idiots PDF.

2022 · PDF

The travels of Capts. Lewis and Clarke from St. Louis, by way of the Missouri and Columbia rivers, to the Pacific ocean; performed in the years 1804, 1805 & 1806, by order of the government of the United States. Containing delineations of the manners, customs, religion, &c. of the Indians, comp. from various authentic sources, and original documents, and a summary of the Statistical view of the Indian nations, from the official communication of Meriwether Lewis. Illustrated with a map of the country, inhabited by the western tribes of Indians

The travels of Capts. Lewis and Clarke from St. Louis, by way of the Missouri and Columbia rivers, to the Pacific ocean; performed in the years 1804, 1805 & 1806, by order of the government of the United States. Containing delineations of the manners, customs, religion, &c. of the Indians, comp. from various authentic sources, and original documents, and a summary of the Statistical view of the Indian nations, from the official communication of Meriwether Lewis. Illustrated with a map of the country, inhabited by the western tribes of Indians

1809 · PDF