From f371309c013d1bf985f54a10a7285a965ce4cc0b Mon Sep 17 00:00:00 2001 From: Wojciech Nagrodzki <278594+wnagrodzki@users.noreply.github.com> Date: Fri, 26 Oct 2018 21:26:26 +0200 Subject: [PATCH] Added "Accessing Singleton" section --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 692d93d..e08fde8 100644 --- a/README.md +++ b/README.md @@ -210,3 +210,9 @@ operation.onComplete { [weak self] result in > This is to avoid deallocation of weakly referenced object during closure execution. > Use `strongSelf` instead of `self` for local variable name until [SR-6156]( https://bugs.swift.org/browse/SR-6156) is fixed. + +### Accessing Singleton + +Do not access singleton instance directly via static method - `Singleton.sharedInstance()`. Decouple from it with dependency injection. + +> If a singleton is used directly there is no way to perform unit tests in isolation from it. Moreover, it may introduce unexpected shared state between unit tests if they are executed in one run.