Minor tweaks
This commit is contained in:
parent
ed390e9ac7
commit
c9033c70cf
|
@ -131,8 +131,8 @@ extension Defaults {
|
|||
}
|
||||
}
|
||||
|
||||
extension Defaults.Key where Value: _DefaultsOptionalType {
|
||||
public convenience init(_ key: String, suite: UserDefaults = .standard) {
|
||||
extension Defaults.Key {
|
||||
public convenience init<T>(_ key: String, suite: UserDefaults = .standard) where Value == T? {
|
||||
self.init(key, default: nil, suite: suite)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ extension Defaults {
|
|||
DefaultsPublisher(suite: key.suite, key: key.name, options: options)
|
||||
.map { _ in () }
|
||||
.eraseToAnyPublisher()
|
||||
}.reduce(initial) { (combined, keyPublisher) in
|
||||
}.reduce(initial) { combined, keyPublisher in
|
||||
combined.merge(with: keyPublisher).eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
|
|
|
@ -83,11 +83,11 @@ extension Defaults {
|
|||
let oldValue: Any?
|
||||
|
||||
init(change: [NSKeyValueChangeKey: Any]) {
|
||||
kind = NSKeyValueChange(rawValue: change[.kindKey] as! UInt)!
|
||||
indexes = change[.indexesKey] as? IndexSet
|
||||
isPrior = change[.notificationIsPriorKey] as? Bool ?? false
|
||||
oldValue = change[.oldKey]
|
||||
newValue = change[.newKey]
|
||||
self.kind = NSKeyValueChange(rawValue: change[.kindKey] as! UInt)!
|
||||
self.indexes = change[.indexesKey] as? IndexSet
|
||||
self.isPrior = change[.notificationIsPriorKey] as? Bool ?? false
|
||||
self.oldValue = change[.oldKey]
|
||||
self.newValue = change[.newKey]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ extension Defaults {
|
|||
lifetimeAssociation?.cancel()
|
||||
}
|
||||
|
||||
private var lifetimeAssociation: LifetimeAssociation? = nil
|
||||
private var lifetimeAssociation: LifetimeAssociation?
|
||||
|
||||
public func tieToLifetime(of weaklyHeldObject: AnyObject) -> Self {
|
||||
lifetimeAssociation = LifetimeAssociation(of: self, with: weaklyHeldObject, deinitHandler: { [weak self] in
|
||||
|
|
|
@ -79,12 +79,12 @@ final class LifetimeAssociation {
|
|||
- Parameter owner: The object whose lifetime extends the target object's lifetime.
|
||||
- Parameter deinitHandler: An optional closure to call when either `owner` or the resulting `LifetimeAssociation` is deallocated.
|
||||
*/
|
||||
init(of target: AnyObject, with owner: AnyObject, deinitHandler: @escaping () -> Void = { }) {
|
||||
init(of target: AnyObject, with owner: AnyObject, deinitHandler: @escaping () -> Void = {}) {
|
||||
let wrappedObject = ObjectLifetimeTracker(for: target, deinitHandler: deinitHandler)
|
||||
|
||||
|
||||
let associatedObjects = LifetimeAssociation.associatedObjects[owner] ?? []
|
||||
LifetimeAssociation.associatedObjects[owner] = associatedObjects + [wrappedObject]
|
||||
|
||||
|
||||
self.wrappedObject = wrappedObject
|
||||
self.owner = owner
|
||||
}
|
||||
|
|
|
@ -366,7 +366,7 @@ final class DefaultsTests: XCTestCase {
|
|||
func testReceiveValueBeforeSubscriptionCombine() {
|
||||
let key = Defaults.Key<String>("receiveValueBeforeSubscription", default: "hello")
|
||||
let expect = expectation(description: "Observation closure being called")
|
||||
|
||||
|
||||
let publisher = Defaults
|
||||
.publisher(key)
|
||||
.compactMap { $0.newValue }
|
||||
|
@ -378,7 +378,7 @@ final class DefaultsTests: XCTestCase {
|
|||
expect.fulfill()
|
||||
}
|
||||
|
||||
Defaults[key] = "world";
|
||||
Defaults[key] = "world"
|
||||
cancellable.cancel()
|
||||
waitForExpectations(timeout: 10)
|
||||
}
|
||||
|
@ -573,7 +573,7 @@ final class DefaultsTests: XCTestCase {
|
|||
let expect = expectation(description: "Observation closure being called")
|
||||
|
||||
weak var observation: Defaults.Observation!
|
||||
observation = Defaults.observe(key, options: []) { change in
|
||||
observation = Defaults.observe(key, options: []) { _ in
|
||||
observation.invalidate()
|
||||
expect.fulfill()
|
||||
}.tieToLifetime(of: self)
|
||||
|
|
Loading…
Reference in New Issue