Created
March 4, 2019 11:28
-
-
Save andr3a88/165c180fee0152c2022485703b5a502b to your computer and use it in GitHub Desktop.
An extension on UserDefaults, which’ll enable us to easily create an instance that has had all of its persisted values completely cleared
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
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.johnsundell.test.\(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