Tweaks
This commit is contained in:
parent
3efef5a28e
commit
55ec93004e
|
@ -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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// swift-tools-version:5.8
|
||||
// swift-tools-version:5.9
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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<T: Defaults.Serializable>(_ value: T) -> Any? {
|
||||
static func toSerializable<T: Defaults.Serializable>(_ 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..<imageCount {
|
||||
guard
|
||||
|
@ -261,7 +261,7 @@ internal let dynamicSharedObject: UnsafeMutableRawPointer = {
|
|||
|
||||
@_transparent
|
||||
@usableFromInline
|
||||
internal func runtimeWarn(
|
||||
func runtimeWarn(
|
||||
_ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String
|
||||
) {
|
||||
#if DEBUG
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue