---
title: "Discussion on \"Exploring Singleton Design Patterns in iOS\" | Hashnode"
description: "Discussion on \"Exploring Singleton Design Patterns in iOS\". The Singleton design pattern ensures that only one instance of a class can be created and used throughout the lifetime of an app."
url: "https://hashnode.com/posts/exploring-singleton-design-patterns-in-ios/662e7a8a61bc94eaae63be0e"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Exploring Singleton Design Patterns in iOS](https://theiosmentor.hashnode.dev/exploring-singleton-design-patterns-in-ios?utm_source=hashnode&utm_medium=feed)

The Singleton design pattern ensures that only one instance of a class can be created and used throughout the lifetime of an app.

Apr 28, 2024 · 4 min read · theiosmentor.hashnode.dev  
Updated May 12, 2024  
Read the article

-   [#design-patterns](https://hashnode.com/tag/design-patterns)
-   [#ios](https://hashnode.com/tag/ios)
-   [#swift](https://hashnode.com/tag/swift)
-   [#singleton-design-pattern](https://hashnode.com/tag/singleton-design-pattern)

## Written by

[Kevin Topollaj](https://hashnode.com/@TheiOSMentor)

@TheiOSMentor · Graz (Austria)

  
[View profile](https://hashnode.com/@TheiOSMentor)

Software Engineer | iOS Developer

Greetings! I am Kevin, an accomplished iOS Software Developer with expertise in software development, architecture, testing, maintenance, and debugging of complex software systems. I have more than five years of experience in developing high-quality iOS apps using Swift programming language, UIKit, SwiftUI and Combine frameworks. With a keen eye for detail and a strong understanding of the latest cutting-edge development tools and procedures, I am dedicated to delivering exceptional results that meet or exceed the needs of my clients. I have a proven track record of working both independently and collaboratively as part of a productive team, and I am able to effectively self-manage during independent projects. Thank you for visiting my personal blog, where I look forward to sharing my knowledge and expertise in iOS development and contributing to the vibrant developer community.

## Responses 1

Markdown supported · ⌘↵ to post

[Maximus](https://hashnode.com/@MaximusiOS)

[Feb 26, 2025](https://hashnode.com/posts/exploring-singleton-design-patterns-in-ios/662e7a8a61bc94eaae63be0e/comment/67becda2077f9e8db484bbe9)

> By default, Swift guarantees thread safety for lazy initialization, ensuring that only one instance is created even in concurrent environments.

This is a wrong assumption. Initialization is not thread-safe, the initialization block can be called multiple times in a concurrent environment. For example:

```
class Example {
    lazy var value: Int = {
        print("Initializing value")
        return 42
    }()
}

let instance = Example()

DispatchQueue.global().async {
    print("Thread 1: \(instance.value)")
}

DispatchQueue.global().async {
    print("Thread 2: \(instance.value)")
}
```

"Initializing value" will be printed twice. See also this discussion - forums.swift.org/t/lazy-property-initialization-question/51085/8 for deeper understanding.
