Rename `Defaults.clear` to `Defaults.removeAll`
This commit is contained in:
parent
90ac6f8802
commit
27c9997134
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:">
|
||||
</FileRef>
|
||||
</Workspace>
|
|
@ -1,4 +1,4 @@
|
|||
// swift-tools-version:5.0
|
||||
// swift-tools-version:5.1
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
|
|
|
@ -161,7 +161,7 @@ public final class Defaults {
|
|||
/**
|
||||
Remove all entries from the `UserDefaults` suite.
|
||||
*/
|
||||
public static func clear(suite: UserDefaults = .standard) {
|
||||
public static func removeAll(suite: UserDefaults = .standard) {
|
||||
for key in suite.dictionaryRepresentation().keys {
|
||||
suite.removeObject(forKey: key)
|
||||
}
|
||||
|
|
|
@ -24,12 +24,12 @@ extension Defaults.Keys {
|
|||
final class DefaultsTests: XCTestCase {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
Defaults.clear()
|
||||
Defaults.removeAll()
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
super.setUp()
|
||||
Defaults.clear()
|
||||
Defaults.removeAll()
|
||||
}
|
||||
|
||||
func testKey() {
|
||||
|
@ -103,12 +103,16 @@ final class DefaultsTests: XCTestCase {
|
|||
XCTAssertEqual(Defaults[.date], newDate)
|
||||
}
|
||||
|
||||
func testClear() {
|
||||
let key = Defaults.Key<Bool>("clear", default: false)
|
||||
func testRemoveAll() {
|
||||
let key = Defaults.Key<Bool>("removeAll", default: false)
|
||||
let key2 = Defaults.Key<Bool>("removeAll2", default: false)
|
||||
Defaults[key] = true
|
||||
Defaults[key2] = true
|
||||
XCTAssertTrue(Defaults[key])
|
||||
Defaults.clear()
|
||||
XCTAssertTrue(Defaults[key2])
|
||||
Defaults.removeAll()
|
||||
XCTAssertFalse(Defaults[key])
|
||||
XCTAssertFalse(Defaults[key2])
|
||||
}
|
||||
|
||||
func testCustomSuite() {
|
||||
|
@ -119,7 +123,7 @@ final class DefaultsTests: XCTestCase {
|
|||
Defaults[key] = true
|
||||
XCTAssertTrue(customSuite[key])
|
||||
XCTAssertTrue(Defaults[key])
|
||||
Defaults.clear(suite: customSuite)
|
||||
Defaults.removeAll(suite: customSuite)
|
||||
}
|
||||
|
||||
func testObserveKey() {
|
||||
|
|
|
@ -274,15 +274,15 @@ Observe changes to a key or an optional key.
|
|||
|
||||
By default, it will also trigger an initial event on creation. This can be useful for setting default values on controls. You can override this behavior with the `options` argument.
|
||||
|
||||
#### `Defaults.clear`
|
||||
#### `Defaults.removeAll`
|
||||
|
||||
```swift
|
||||
Defaults.clear(suite: UserDefaults = .standard)
|
||||
Defaults.removeAll(suite: UserDefaults = .standard)
|
||||
```
|
||||
|
||||
Type: `func`
|
||||
|
||||
Clear the user defaults.
|
||||
Remove all entries from the `UserDefaults` suite.
|
||||
|
||||
|
||||
## FAQ
|
||||
|
|
Loading…
Reference in New Issue