Tag Archives: Singleton

Singletons in Swift


via iOS Development | Singleton Swift.

In this post, I will demonstrate one particular way of creating singletons in Swift. But, before starting, let me just say: Swift is a very powerful programming language that allows developers to construct the same functionality in multiple ways. Therefore, the following example is just one way of building a singleton in Swift.

Generally, I discourage the use of singletons, as instantiating an object that will last forever is not good design. Instead, I prefer letting ARC do the memory management and letting ARC decide when to release an object or keep it alive. Additionally, there’s always an alternative way to build what you are trying to do with a singleton.

Nonetheless, despite my recommendations, I will demonstrate a way of building a singleton or a shared object in Swift, just in case you absolutely need one.

Java EE Pitfalls #1: Ignore the default lock of a Singleton


Java EE Pitfalls #1: Ignore the default lock of a Singleton

EJB Singleton Beans were introduced by the EJB 3.1 specification and are often used to store cached data. This means, we try to improve the performance of our application by using a Singleton. In general, this works quite well. Especially if there are not too many calls in parallel. But it changes if we ignore the default lock and the number of parallel calls increases.