Skip to content

Commit

Permalink
Add support for serializing Color.Resolved (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus authored Apr 20, 2024
1 parent 17fddec commit ce45591
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Sources/Defaults/Defaults+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ extension Color: Defaults.Serializable {
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 {
public static var bridge: Defaults.RangeBridge<Range> { Defaults.RangeBridge() }
}
Expand Down
22 changes: 21 additions & 1 deletion Tests/DefaultsTests/DefaultsColorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SwiftUI
import Defaults
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 {
override func setUp() {
super.setUp()
Expand All @@ -22,3 +22,23 @@ final class DefaultsColorTests: XCTestCase {
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)
}
}
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Add `https://github.com/sindresorhus/Defaults` in the [“Swift Package Manager
- `NSColor` (macOS)
- `UIColor` (iOS)
- `Color` [^1] (SwiftUI)
- `Color.Resolved` [^1] (SwiftUI)
- `Codable`
- `NSSecureCoding`
- `Range`, `ClosedRange`
Expand Down

0 comments on commit ce45591

Please sign in to comment.