Skip to content

Commit

Permalink
Remove Defaults.publisherAll until #42 is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 18, 2020
1 parent c20b7d8 commit 5df16e0
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 51 deletions.
21 changes: 0 additions & 21 deletions Sources/Defaults/Observation+Combine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void, Never> {
let publisher =
NotificationCenter.default.publisher(for: UserDefaults.didChangeNotification)
.map { _ in () }

if initialEvent {
return publisher
.prepend(())
.eraseToAnyPublisher()
} else {
return publisher
.eraseToAnyPublisher()
}
}
}

#endif
18 changes: 0 additions & 18 deletions Tests/DefaultsTests/DefaultsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<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, *)
func testObserveMultipleKeysCombine() {
let key1 = Defaults.Key<String>("observeKey1", default: "x")
Expand Down
12 changes: 0 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<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`

```swift
Expand Down

0 comments on commit 5df16e0

Please sign in to comment.