Add support for serializing `Color.Resolved` (#171)
This commit is contained in:
parent
17fddec4d9
commit
ce45591c09
|
@ -145,6 +145,9 @@ extension Color: Defaults.Serializable {
|
||||||
public static let bridge = Defaults.ColorBridge()
|
public static let bridge = Defaults.ColorBridge()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(macOS 14.0, iOS 17.0, tvOS 17.0, watchOS 9.0, visionOS 1.0, *)
|
||||||
|
extension Color.Resolved: Defaults.Serializable {}
|
||||||
|
|
||||||
extension Range: Defaults.RangeSerializable where Bound: Defaults.Serializable {
|
extension Range: Defaults.RangeSerializable where Bound: Defaults.Serializable {
|
||||||
public static var bridge: Defaults.RangeBridge<Range> { Defaults.RangeBridge() }
|
public static var bridge: Defaults.RangeBridge<Range> { Defaults.RangeBridge() }
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import SwiftUI
|
||||||
import Defaults
|
import Defaults
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
@available(iOS 15, tvOS 15, watchOS 8, visionOS 1.0, *)
|
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, visionOS 1.0, *)
|
||||||
final class DefaultsColorTests: XCTestCase {
|
final class DefaultsColorTests: XCTestCase {
|
||||||
override func setUp() {
|
override func setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
|
@ -22,3 +22,23 @@ final class DefaultsColorTests: XCTestCase {
|
||||||
XCTAssertEqual(Defaults[key]?.cgColor, fixture.cgColor)
|
XCTAssertEqual(Defaults[key]?.cgColor, fixture.cgColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(macOS 14, iOS 17, tvOS 17, watchOS 9, visionOS 1.0, *)
|
||||||
|
final class DefaultsColorResolvedTests: XCTestCase {
|
||||||
|
override func setUp() {
|
||||||
|
super.setUp()
|
||||||
|
Defaults.removeAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tearDown() {
|
||||||
|
super.tearDown()
|
||||||
|
Defaults.removeAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
func test() {
|
||||||
|
let fixture = Color(.displayP3, red: 1, green: 0.3, blue: 0.7, opacity: 1).resolve(in: .init())
|
||||||
|
let key = Defaults.Key<Color.Resolved?>("independentColorResolvedKey")
|
||||||
|
Defaults[key] = fixture
|
||||||
|
XCTAssertEqual(Defaults[key]?.cgColor, fixture.cgColor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ Add `https://github.com/sindresorhus/Defaults` in the [“Swift Package Manager
|
||||||
- `NSColor` (macOS)
|
- `NSColor` (macOS)
|
||||||
- `UIColor` (iOS)
|
- `UIColor` (iOS)
|
||||||
- `Color` [^1] (SwiftUI)
|
- `Color` [^1] (SwiftUI)
|
||||||
|
- `Color.Resolved` [^1] (SwiftUI)
|
||||||
- `Codable`
|
- `Codable`
|
||||||
- `NSSecureCoding`
|
- `NSSecureCoding`
|
||||||
- `Range`, `ClosedRange`
|
- `Range`, `ClosedRange`
|
||||||
|
|
Loading…
Reference in New Issue