Minor tweaks
This commit is contained in:
parent
ed390e9ac7
commit
c9033c70cf
|
@ -131,8 +131,8 @@ extension Defaults {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Defaults.Key where Value: _DefaultsOptionalType {
|
extension Defaults.Key {
|
||||||
public convenience init(_ key: String, suite: UserDefaults = .standard) {
|
public convenience init<T>(_ key: String, suite: UserDefaults = .standard) where Value == T? {
|
||||||
self.init(key, default: nil, suite: suite)
|
self.init(key, default: nil, suite: suite)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,7 @@ extension Defaults {
|
||||||
DefaultsPublisher(suite: key.suite, key: key.name, options: options)
|
DefaultsPublisher(suite: key.suite, key: key.name, options: options)
|
||||||
.map { _ in () }
|
.map { _ in () }
|
||||||
.eraseToAnyPublisher()
|
.eraseToAnyPublisher()
|
||||||
}.reduce(initial) { (combined, keyPublisher) in
|
}.reduce(initial) { combined, keyPublisher in
|
||||||
combined.merge(with: keyPublisher).eraseToAnyPublisher()
|
combined.merge(with: keyPublisher).eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,11 +83,11 @@ extension Defaults {
|
||||||
let oldValue: Any?
|
let oldValue: Any?
|
||||||
|
|
||||||
init(change: [NSKeyValueChangeKey: Any]) {
|
init(change: [NSKeyValueChangeKey: Any]) {
|
||||||
kind = NSKeyValueChange(rawValue: change[.kindKey] as! UInt)!
|
self.kind = NSKeyValueChange(rawValue: change[.kindKey] as! UInt)!
|
||||||
indexes = change[.indexesKey] as? IndexSet
|
self.indexes = change[.indexesKey] as? IndexSet
|
||||||
isPrior = change[.notificationIsPriorKey] as? Bool ?? false
|
self.isPrior = change[.notificationIsPriorKey] as? Bool ?? false
|
||||||
oldValue = change[.oldKey]
|
self.oldValue = change[.oldKey]
|
||||||
newValue = change[.newKey]
|
self.newValue = change[.newKey]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ extension Defaults {
|
||||||
lifetimeAssociation?.cancel()
|
lifetimeAssociation?.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var lifetimeAssociation: LifetimeAssociation? = nil
|
private var lifetimeAssociation: LifetimeAssociation?
|
||||||
|
|
||||||
public func tieToLifetime(of weaklyHeldObject: AnyObject) -> Self {
|
public func tieToLifetime(of weaklyHeldObject: AnyObject) -> Self {
|
||||||
lifetimeAssociation = LifetimeAssociation(of: self, with: weaklyHeldObject, deinitHandler: { [weak self] in
|
lifetimeAssociation = LifetimeAssociation(of: self, with: weaklyHeldObject, deinitHandler: { [weak self] in
|
||||||
|
|
|
@ -378,7 +378,7 @@ final class DefaultsTests: XCTestCase {
|
||||||
expect.fulfill()
|
expect.fulfill()
|
||||||
}
|
}
|
||||||
|
|
||||||
Defaults[key] = "world";
|
Defaults[key] = "world"
|
||||||
cancellable.cancel()
|
cancellable.cancel()
|
||||||
waitForExpectations(timeout: 10)
|
waitForExpectations(timeout: 10)
|
||||||
}
|
}
|
||||||
|
@ -573,7 +573,7 @@ final class DefaultsTests: XCTestCase {
|
||||||
let expect = expectation(description: "Observation closure being called")
|
let expect = expectation(description: "Observation closure being called")
|
||||||
|
|
||||||
weak var observation: Defaults.Observation!
|
weak var observation: Defaults.Observation!
|
||||||
observation = Defaults.observe(key, options: []) { change in
|
observation = Defaults.observe(key, options: []) { _ in
|
||||||
observation.invalidate()
|
observation.invalidate()
|
||||||
expect.fulfill()
|
expect.fulfill()
|
||||||
}.tieToLifetime(of: self)
|
}.tieToLifetime(of: self)
|
||||||
|
|
Loading…
Reference in New Issue