Skip to content

Instantly share code, notes, and snippets.

@hossamghareeb
Created January 6, 2021 17:59
Show Gist options
  • Save hossamghareeb/572827f889fc68eb7d7e4b4ed990f8a8 to your computer and use it in GitHub Desktop.
Save hossamghareeb/572827f889fc68eb7d7e4b4ed990f8a8 to your computer and use it in GitHub Desktop.
Subclass then override for singletons
class ViewController {
var manager: Singleton {
return Singleton.shared
}
}
// in unit testing target
class TestingViewController: ViewController {
override var manager: Singleton { Singleton() }
}
// Usage
func testViewController() {
let vc = TestingViewController()
// assert
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment