Cross-Platform Swift: Networking

Episode #292 • Aug 26, 2024 • Subscriber-Only

Let’s dial up the complexity of our Wasm application! We’ll introduce some async logic in the form of a network request. We’ll take steps to not only control this dependency, but we’ll do so across both Apple and Wasm platforms, and we’ll isolate its interface from its live implementation to speed up our builds and reduce our app’s size.

Previous episode
Cross-Platform Swift: Networking
Next episode
Locked

Unlock This Episode

Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.

Sign in with GitHub

Introduction

Stephen

I don’t know about you, but I think this pretty incredible. We have a 100% pure Swift code base that is powering a web app. And even better, we are using the same model that we used over in UIKit and SwiftUI. This is showing a possible vision for cross-platform development in Swift. One model powering features on two vastly different platforms: iOS and the web. And it’s all thanks to the cross-platform observe function that comes with our Swift Navigation library, as well as Swift’s amazing Observation framework.

Brandon

But we are still missing some of the most important behavior in the feature, which is the network request that loads a fact from the server and presents it to the user. This is going to be a little more difficult than everything we have accomplished so far because it involves new APIs for making network requests and it involves asynchronous work.

Let’s dig in.

Making network requests


References

  • Swift for WebAssembly - How To Use Swift In Your Web App
    Steven Van Impe

    A talk from SwiftCraft 2024: WebAssembly is a rapidly growing technology that provides great opportunities for Swift developers. This talk will introduce Swift developers to WebAssembly, and demonstrate how they can run Swift in the browser, call JavaScript from Swift to access the DOM, add Swift modules to web apps, and so much more. A live demo will show how a single Swift codebase can power not just an iOS app, but also a web app, and a back-end.

  • Batteries Not Included: Beyond Xcode
    Kabir Oberai

    A talk from Swift TO 2023: A confrontation of the notion that Xcode+macOS are the only way to develop apps for Apple platforms. We’ll discover what it takes to build apps in other IDEs like Visual Studio Code, as well as on non-Apple platforms, unveiling the secrets of cross-compilation to build, sign, and deploy iOS apps on Windows and Linux.

  • Swift WebAssembly + GoodNotes, a cross-platform story!
    Pedro Gómez • Nov 19, 2022

    A talk from NSSpain 2022 discussing how Goodnotes uses Swift Wasm in their application: When a company implements 100% of the codebase in a language like Swift, there is a chance that in the future you may need to implement something that is not an iOS app with the same code, something like a web page maybe? This talk relates how we’ve reused most of the already implemented code in GoodNotes iOS app to create a web project we can reuse in different platforms, the technical approach we fo llowed, challenges and solutions applied.

Downloads

Get started with our free plan

Our free plan includes 1 subscriber-only episode of your choice, access to 64 free episodes with transcripts and code samples, and weekly updates from our newsletter.

View plans and pricing