---
title: Managing a Shared Resource Using a Singleton
framework: swift
role: article
role_heading: Article
path: swift/managing-a-shared-resource-using-a-singleton
---

# Managing a Shared Resource Using a Singleton

Provide access to a shared resource using a single, shared class instance.

## Overview

Overview You use singletons to provide a globally accessible, shared instance of a class. You can create your own singletons as a way to provide a unified access point to a resource or service that’s shared across an app, like an audio channel to play sound effects or a network manager to make HTTP requests. Create a Singleton You create simple singletons using a static type property, which is guaranteed to be lazily initialized only once, even when accessed across multiple threads simultaneously: class Singleton {     static let shared = Singleton() } If you need to perform additional setup beyond initialization, you can assign the result of the invocation of a closure to the global constant: class Singleton {     static let shared: Singleton = {         let instance = Singleton()         // setup code         return instance     }() }

## See Also

### Common Patterns

- [Using Key-Value Observing in Swift](swift/using-key-value-observing-in-swift.md)
- [Using Delegates to Customize Object Behavior](swift/using-delegates-to-customize-object-behavior.md)
- [About Imported Cocoa Error Parameters](swift/about-imported-cocoa-error-parameters.md)
- [Handling Cocoa Errors in Swift](swift/handling-cocoa-errors-in-swift.md)
