How to declare Swift protocol for a specific class

Protocols enable us to define a blueprint of methods and properties suited to a particular task. Classes, structures, and enums can then adopt protocols and provide their implementation of those methods and properties. With Swift 5, protocol definitions can constrain their conforming types to those that subclass a particular class. In this post, Sarun Wongpatcharapakorn describes how to add such a constraint and explains the benefits of doing so.

Building a Multi-platform App with SwiftUI

The Introduction to SwiftUI session at WWDC 2020 included content that focused on using SwiftUI to build multi-platform apps - i.e apps that work on both iOS and macOS. Building such apps can be done by separately building for each platform from a single codebase, or creating a Mac Catalyst app which runs an app built for iPad on macOS. In this post, Rick Wierenga looks at the former, providing a tutorial that shows us how to use a single codebase to build a HackerNews app for each platform.

Memoization of Swift properties

Memoization is an optimization technique where the results of expensive computations (e.g function calls or computed properties) are stored, and these cached results are returned when the inputs to future computations are unchanged. In this Swift evolution pitch, Justin Reusch proposes adding keywords to Swift which tell the compiler when to synthesize boilerplate code to support the memoization of computed properties. I think this would be a good addition to the language.

Dependency Injection via Property Wrappers

Property Wrappers in Swift allow us to add a layer of separation between code that manages how a property is stored and the code that defines a property. It's a powerful feature with a lot of potential use cases. Dependency injection is a software engineering technique used to supply dependencies to an object or value type. In this post, Kilo Loco demonstrates how we can use Swift property wrappers to pass dependencies to a SwiftUI view. It's a cool idea.