Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Oct 4, 2023
1 parent 3efef5a commit 55ec930
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.8
// swift-tools-version:5.9
import PackageDescription

let package = Package(
Expand Down
42 changes: 21 additions & 21 deletions Sources/Defaults/Defaults+AnySerializable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion Sources/Defaults/Defaults+Bridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Defaults/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() }

Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Defaults/UserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension UserDefaults {
}

func _set<Value: Defaults.Serializable>(_ key: String, to value: Value) {
if (value as? _DefaultsOptionalProtocol)?.isNil == true {
if (value as? _DefaultsOptionalProtocol)?._defaults_isNil == true {
removeObject(forKey: key)
return
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/Defaults/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}


Expand Down Expand Up @@ -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 }
}
Expand Down Expand Up @@ -215,7 +215,7 @@ extension Defaults.Serializable {
```
*/
@usableFromInline
internal static func toSerializable<T: Defaults.Serializable>(_ value: T) -> Any? {
static func toSerializable<T: Defaults.Serializable>(_ value: T) -> Any? {
if T.isNativelySupportedType {
return value
}
Expand All @@ -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..<imageCount {
guard
Expand All @@ -261,7 +261,7 @@ internal let dynamicSharedObject: UnsafeMutableRawPointer = {

@_transparent
@usableFromInline
internal func runtimeWarn(
func runtimeWarn(
_ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String
) {
#if DEBUG
Expand Down
4 changes: 2 additions & 2 deletions Tests/DefaultsTests/DefaultsCustomBridgeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand Down

0 comments on commit 55ec930

Please sign in to comment.