Added "Accessing Singleton" section

This commit is contained in:
Wojciech Nagrodzki 2018-10-26 21:26:26 +02:00
parent 3bf12d0471
commit f371309c01
Signed by: wnagrodzki
GPG key ID: E9D0EB0302264569

View file

@ -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.