The Singleton pattern and its concurrency issues in Swift

Andreea Andro
3 min readOct 18, 2022

The Singleton pattern is used to ensure there is only one instance of a type. If not implemented well, may bring concurrency issues: data-corruption and crashes.

Let’s start with a read-only singleton:
- safe even if we read the shared instance from different threads running in parallel

final public class AppSettings {

public static let shared = AppSettings()
private var settings: [String: Any] = ["Theme": "Light"]
private init() {}

--

--