diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0490e86..604c650 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,7 +7,7 @@ jobs: runs-on: macos-13 steps: - uses: actions/checkout@v3 - - run: sudo xcode-select -switch /Applications/Xcode_14.3.app + - run: sudo xcode-select -switch /Applications/Xcode_15.0.app - run: swift test lint: runs-on: ubuntu-latest diff --git a/Package.swift b/Package.swift index 110a764..8dff91b 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.8 +// swift-tools-version:5.9 import PackageDescription let package = Package( diff --git a/Sources/Defaults/Defaults+AnySerializable.swift b/Sources/Defaults/Defaults+AnySerializable.swift index 17010ab..5c69461 100644 --- a/Sources/Defaults/Defaults+AnySerializable.swift +++ b/Sources/Defaults/Defaults+AnySerializable.swift @@ -106,45 +106,45 @@ extension Defaults.AnySerializable: Equatable { public static func == (lhs: Self, rhs: Self) -> Bool { switch (lhs.value, rhs.value) { case (let lhs as Data, let rhs as Data): - return lhs == rhs + lhs == rhs case (let lhs as Date, let rhs as Date): - return lhs == rhs + lhs == rhs case (let lhs as Bool, let rhs as Bool): - return lhs == rhs + lhs == rhs case (let lhs as UInt8, let rhs as UInt8): - return lhs == rhs + lhs == rhs case (let lhs as Int8, let rhs as Int8): - return lhs == rhs + lhs == rhs case (let lhs as UInt16, let rhs as UInt16): - return lhs == rhs + lhs == rhs case (let lhs as Int16, let rhs as Int16): - return lhs == rhs + lhs == rhs case (let lhs as UInt32, let rhs as UInt32): - return lhs == rhs + lhs == rhs case (let lhs as Int32, let rhs as Int32): - return lhs == rhs + lhs == rhs case (let lhs as UInt64, let rhs as UInt64): - return lhs == rhs + lhs == rhs case (let lhs as Int64, let rhs as Int64): - return lhs == rhs + lhs == rhs case (let lhs as UInt, let rhs as UInt): - return lhs == rhs + lhs == rhs case (let lhs as Int, let rhs as Int): - return lhs == rhs + lhs == rhs case (let lhs as Float, let rhs as Float): - return lhs == rhs + lhs == rhs case (let lhs as Double, let rhs as Double): - return lhs == rhs + lhs == rhs case (let lhs as CGFloat, let rhs as CGFloat): - return lhs == rhs + lhs == rhs case (let lhs as String, let rhs as String): - return lhs == rhs + lhs == rhs case (let lhs as [AnyHashable: Any], let rhs as [AnyHashable: Any]): - return lhs.toDictionary() == rhs.toDictionary() + lhs.toDictionary() == rhs.toDictionary() case (let lhs as [Any], let rhs as [Any]): - return lhs.toSequence() == rhs.toSequence() + lhs.toSequence() == rhs.toSequence() default: - return false + false } } } @@ -193,7 +193,7 @@ extension Defaults.AnySerializable: ExpressibleByDictionaryLiteral { extension Defaults.AnySerializable: _DefaultsOptionalProtocol { // Since `nil` cannot be assigned to `Any`, we use `Void` instead of `nil`. - public var isNil: Bool { value is Void } + public var _defaults_isNil: Bool { value is Void } } extension Sequence { diff --git a/Sources/Defaults/Defaults+Bridge.swift b/Sources/Defaults/Defaults+Bridge.swift index c736b8b..8ea2fe2 100644 --- a/Sources/Defaults/Defaults+Bridge.swift +++ b/Sources/Defaults/Defaults+Bridge.swift @@ -15,7 +15,9 @@ extension Defaults.CodableBridge { // Some codable values like URL and enum are encoded as a top-level // string which JSON can't handle, so we need to wrap it in an array // We need this: https://forums.swift.org/t/allowing-top-level-fragments-in-jsondecoder/11750 - let data = try JSONEncoder().encode([value]) + let jsonEncoder = JSONEncoder() + jsonEncoder.outputFormatting = .sortedKeys + let data = try jsonEncoder.encode([value]) return String(String(data: data, encoding: .utf8)!.dropFirst().dropLast()) } catch { print(error) diff --git a/Sources/Defaults/Defaults.swift b/Sources/Defaults/Defaults.swift index 6fa37d6..d6c3036 100644 --- a/Sources/Defaults/Defaults.swift +++ b/Sources/Defaults/Defaults.swift @@ -95,7 +95,7 @@ extension Defaults { - A `bridge` cannot deserialize `Value` from `UserDefaults` */ @usableFromInline - internal let defaultValueGetter: () -> Value + let defaultValueGetter: () -> Value public var defaultValue: Value { defaultValueGetter() } @@ -116,7 +116,7 @@ extension Defaults { super.init(name: name, suite: suite) - if (defaultValue as? _DefaultsOptionalProtocol)?.isNil == true { + if (defaultValue as? _DefaultsOptionalProtocol)?._defaults_isNil == true { return } diff --git a/Sources/Defaults/UserDefaults.swift b/Sources/Defaults/UserDefaults.swift index 703d0bc..5e1bc2f 100644 --- a/Sources/Defaults/UserDefaults.swift +++ b/Sources/Defaults/UserDefaults.swift @@ -10,7 +10,7 @@ extension UserDefaults { } func _set(_ key: String, to value: Value) { - if (value as? _DefaultsOptionalProtocol)?.isNil == true { + if (value as? _DefaultsOptionalProtocol)?._defaults_isNil == true { removeObject(forKey: key) return } diff --git a/Sources/Defaults/Utilities.swift b/Sources/Defaults/Utilities.swift index 2df51c7..cb37ffe 100644 --- a/Sources/Defaults/Utilities.swift +++ b/Sources/Defaults/Utilities.swift @@ -132,11 +132,11 @@ public protocol _DefaultsOptionalProtocol: ExpressibleByNilLiteral { /** This is useful as you cannot compare `_OptionalType` to `nil`. */ - var isNil: Bool { get } + var _defaults_isNil: Bool { get } } extension Optional: _DefaultsOptionalProtocol { - public var isNil: Bool { self == nil } + public var _defaults_isNil: Bool { self == nil } } @@ -166,7 +166,7 @@ extension Collection { extension Defaults { @usableFromInline - internal static func isValidKeyPath(name: String) -> Bool { + static func isValidKeyPath(name: String) -> Bool { // The key must be ASCII, not start with @, and cannot contain a dot. !name.starts(with: "@") && name.allSatisfy { $0 != "." && $0.isASCII } } @@ -215,7 +215,7 @@ extension Defaults.Serializable { ``` */ @usableFromInline - internal static func toSerializable(_ value: T) -> Any? { + static func toSerializable(_ value: T) -> Any? { if T.isNativelySupportedType { return value } @@ -240,7 +240,7 @@ Get SwiftUI dynamic shared object. Reference: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/dyld.3.html */ @usableFromInline -internal let dynamicSharedObject: UnsafeMutableRawPointer = { +let dynamicSharedObject: UnsafeMutableRawPointer = { let imageCount = _dyld_image_count() for imageIndex in 0.. Bool, _ message: @autoclosure () -> String ) { #if DEBUG diff --git a/Tests/DefaultsTests/DefaultsCustomBridgeTests.swift b/Tests/DefaultsTests/DefaultsCustomBridgeTests.swift index 5da6db9..9cb8e3a 100644 --- a/Tests/DefaultsTests/DefaultsCustomBridgeTests.swift +++ b/Tests/DefaultsTests/DefaultsCustomBridgeTests.swift @@ -205,7 +205,7 @@ final class DefaultsCustomBridge: XCTestCase { XCTFail("rawValue should not be nil") return } - XCTAssertEqual(rawValue, [#"{"minute":0,"hour":1}"#, #"{"minute":0,"hour":2}"#]) + XCTAssertEqual(rawValue, [#"{"hour":1,"minute":0}"#, #"{"hour":2,"minute":0}"#]) let next_start = PlainHourMinuteTime(hour: 3, minute: 58) let next_end = PlainHourMinuteTime(hour: 4, minute: 59) let next_range = PlainHourMinuteTimeRange(start: next_start, end: next_end) @@ -218,7 +218,7 @@ final class DefaultsCustomBridge: XCTestCase { XCTFail("nextRawValue should not be nil") return } - XCTAssertEqual(nextRawValue, [#"{"minute":58,"hour":3}"#, #"{"minute":59,"hour":4}"#]) + XCTAssertEqual(nextRawValue, [#"{"hour":3,"minute":58}"#, #"{"hour":4,"minute":59}"#]) } func testType() {