Better Programming

Advice for programmers.

Follow publication

Member-only story

Networking With Combine and SwiftUI

Perform networking calls using reactive programming

Peter Friese
Better Programming
Published in
8 min readJan 19, 2022
Header image based on the “network” icon from SF Symbols

Not keeping the UI up to date across the different parts of an app can result in an infuriatingly bad user experience, and I am sure we all have at least one or two apps in mind that are notorious for this kind of behaviour.

Writing apps that keep the state in sync across the UI and the underlying data model has traditionally been a difficult task, and the development community has come up with plenty of approaches to address this challenge in more or less developer-friendly ways.

Reactive programming is one such approach, and SwiftUI’s reactive state management makes this a lot easier by introducing the notion of a source of truth that can be shared across your app using SwiftUI’s property wrappers such as @EnvironmentObject, @ObservedObject, and @StateObject.

This source of truth usually is your in-memory data model — but as we all know, no application exists in isolation. Most modern apps need to access the network (or other services) at some point, and this means introducing asynchronous behaviour to your app. There are plenty of ways to deal with asynchronous behaviour in our apps: delegate methods, callback handlers, Combine, and async/await, to name just a few.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Peter Friese
Peter Friese

Written by Peter Friese

Google Developer Advocate with the Firebase team 🔥

Responses (2)

Write a response

What I applaud in Mr. Carnevale's piece is an attempt to shift the attention away from affirmative action and college (now, there's a silo) to education reform of K-12 education. In my view, the problem starts when humans by and large support their…

Affirmative Action still around?

interesting