Last active
March 7, 2019 09:49
-
-
Save JanGorman/aeb31347bda571771b60bec55ba3ad9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Combine app + shared defaults into one | |
| extension UserDefaults { | |
| static var shared: UserDefaults { | |
| let combined = UserDefaults.standard | |
| combined.addSuite(named: "com.schnaub.app") | |
| return combined | |
| } | |
| } | |
| // Unit test instance that clears all values before the test is run | |
| extension UserDefaults { | |
| static func makeClearedInstance(for functionName: StaticString = #function, | |
| inFile fileName: StaticString = #file) -> UserDefaults { | |
| let className = "\(fileName)".split(separator: ".")[0] | |
| let testName = "\(functionName)".split(separator: "(")[0] | |
| let suiteName = "com.schnaub.text.\(className).\(testName)" | |
| let defaults = self.init(suiteName: suiteName)! | |
| defaults.removePersistentDomain(forName: suiteName) | |
| return defaults | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment