Remove `Defaults.publisherAll` until #42 is fixed

This commit is contained in:
Sindre Sorhus 2020-04-18 14:21:31 +08:00
parent c20b7d820c
commit 5df16e0d2e
3 changed files with 0 additions and 51 deletions

View File

@ -149,27 +149,6 @@ extension Defaults {
return combinedPublisher return combinedPublisher
} }
/**
Convenience `Publisher` for all `UserDefaults` key change events. A wrapper around the `UserDefaults.didChangeNotification`.
- Parameter initialEvent: Trigger an initial event immediately.
*/
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, iOSApplicationExtension 13.0, macOSApplicationExtension 10.15, tvOSApplicationExtension 13.0, watchOSApplicationExtension 6.0, *)
public static func publisherAll(initialEvent: Bool = true) -> AnyPublisher<Void, Never> {
let publisher =
NotificationCenter.default.publisher(for: UserDefaults.didChangeNotification)
.map { _ in () }
if initialEvent {
return publisher
.prepend(())
.eraseToAnyPublisher()
} else {
return publisher
.eraseToAnyPublisher()
}
}
} }
#endif #endif

View File

@ -285,24 +285,6 @@ final class DefaultsTests: XCTestCase {
waitForExpectations(timeout: 10) waitForExpectations(timeout: 10)
} }
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, iOSApplicationExtension 13.0, macOSApplicationExtension 10.15, tvOSApplicationExtension 13.0, watchOSApplicationExtension 6.0, *)
func testObserveAllCombine() {
let key = Defaults.Key<Bool>("observeAllKey", default: false)
let expect = expectation(description: "Observation closure being called")
let publisher = Defaults.publisherAll().collect(3)
let cancellable = publisher.sink { actualValues in
XCTAssertEqual(3, actualValues.count)
expect.fulfill()
}
Defaults[key] = true
Defaults[key] = false
cancellable.cancel()
waitForExpectations(timeout: 10)
}
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, iOSApplicationExtension 13.0, macOSApplicationExtension 10.15, tvOSApplicationExtension 13.0, watchOSApplicationExtension 6.0, *) @available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, iOSApplicationExtension 13.0, macOSApplicationExtension 10.15, tvOSApplicationExtension 13.0, watchOSApplicationExtension 6.0, *)
func testObserveMultipleKeysCombine() { func testObserveMultipleKeysCombine() {
let key1 = Defaults.Key<String>("observeKey1", default: "x") let key1 = Defaults.Key<String>("observeKey1", default: "x")

View File

@ -397,18 +397,6 @@ Type: `func`
Available on macOS 10.15+, iOS 13.0+, tvOS 13.0+, and watchOS 6.0+. Available on macOS 10.15+, iOS 13.0+, tvOS 13.0+, and watchOS 6.0+.
#### `Defaults.publisherAll`
```swift
Defaults.publisherAll(initialEvent: Bool = true) -> AnyPublisher<UserDefaults, Never>
```
Convenience [Publisher](https://developer.apple.com/documentation/combine/publisher) for all `UserDefaults` key change events. A wrapper around the [`UserDefaults.didChangeNotification` notification](https://developer.apple.com/documentation/foundation/userdefaults/1408206-didchangenotification).
- Parameter `initialEvent`: Trigger an initial event immediately.
Available on macOS 10.15+, iOS 13.0+, tvOS 13.0+, and watchOS 6.0+.
#### `Defaults.removeAll` #### `Defaults.removeAll`
```swift ```swift