From 5df16e0d2e0c27f2a4d014d587603a5ffd5c13d3 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 18 Apr 2020 14:21:31 +0800 Subject: [PATCH] Remove `Defaults.publisherAll` until #42 is fixed --- Sources/Defaults/Observation+Combine.swift | 21 --------------------- Tests/DefaultsTests/DefaultsTests.swift | 18 ------------------ readme.md | 12 ------------ 3 files changed, 51 deletions(-) diff --git a/Sources/Defaults/Observation+Combine.swift b/Sources/Defaults/Observation+Combine.swift index d1463ca..5817431 100644 --- a/Sources/Defaults/Observation+Combine.swift +++ b/Sources/Defaults/Observation+Combine.swift @@ -149,27 +149,6 @@ extension Defaults { 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 { - let publisher = - NotificationCenter.default.publisher(for: UserDefaults.didChangeNotification) - .map { _ in () } - - if initialEvent { - return publisher - .prepend(()) - .eraseToAnyPublisher() - } else { - return publisher - .eraseToAnyPublisher() - } - } } #endif diff --git a/Tests/DefaultsTests/DefaultsTests.swift b/Tests/DefaultsTests/DefaultsTests.swift index 56e98e9..c1d323b 100644 --- a/Tests/DefaultsTests/DefaultsTests.swift +++ b/Tests/DefaultsTests/DefaultsTests.swift @@ -285,24 +285,6 @@ final class DefaultsTests: XCTestCase { 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("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, *) func testObserveMultipleKeysCombine() { let key1 = Defaults.Key("observeKey1", default: "x") diff --git a/readme.md b/readme.md index 54c7ae2..be1a6e2 100644 --- a/readme.md +++ b/readme.md @@ -397,18 +397,6 @@ Type: `func` Available on macOS 10.15+, iOS 13.0+, tvOS 13.0+, and watchOS 6.0+. -#### `Defaults.publisherAll` - -```swift -Defaults.publisherAll(initialEvent: Bool = true) -> AnyPublisher -``` - -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` ```swift