From e19bb784e8cb4c173a11c841f8be7ca3534050d9 Mon Sep 17 00:00:00 2001 From: Muukii Date: Fri, 20 Sep 2024 22:38:48 +0900 Subject: [PATCH 1/2] WIP --- JAYSON.xcodeproj/project.pbxproj | 4 +-- Sources/JAYSON/JSON+OptionalProperty.swift | 4 +-- Sources/JAYSON/JSON.swift | 32 +++++++++++----------- Sources/JAYSON/JSONWritableType.swift | 5 ++-- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/JAYSON.xcodeproj/project.pbxproj b/JAYSON.xcodeproj/project.pbxproj index 8025497..e9c5bd6 100644 --- a/JAYSON.xcodeproj/project.pbxproj +++ b/JAYSON.xcodeproj/project.pbxproj @@ -354,7 +354,7 @@ SUPPORTS_MACCATALYST = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; @@ -407,7 +407,7 @@ SUPPORTED_PLATFORMS = "watchsimulator watchos macosx iphonesimulator iphoneos driverkit appletvsimulator appletvos"; SUPPORTS_MACCATALYST = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = "1,2"; TVOS_DEPLOYMENT_TARGET = 9.0; VALIDATE_PRODUCT = YES; diff --git a/Sources/JAYSON/JSON+OptionalProperty.swift b/Sources/JAYSON/JSON+OptionalProperty.swift index e914851..1b550d7 100644 --- a/Sources/JAYSON/JSON+OptionalProperty.swift +++ b/Sources/JAYSON/JSON+OptionalProperty.swift @@ -25,7 +25,7 @@ import Foundation extension JSON { public var dictionary: [String : JSON]? { - return (source as? [String : Any])?.reduce([String : JSON]()) { dic, element in + return (source as? [String : Any & Sendable])?.reduce([String : JSON]()) { dic, element in var dic = dic dic[element.key] = JSON(source: element.value, breadcrumb: Breadcrumb(json: self, key: element.key)) return dic @@ -33,7 +33,7 @@ extension JSON { } public var array: [JSON]? { - return (source as? [Any])? + return (source as? [Any & Sendable])? .enumerated() .map { JSON( diff --git a/Sources/JAYSON/JSON.swift b/Sources/JAYSON/JSON.swift index b197d85..11e580c 100644 --- a/Sources/JAYSON/JSON.swift +++ b/Sources/JAYSON/JSON.swift @@ -23,16 +23,16 @@ import Foundation public enum JSONError: Error { - case notFoundKeyPath(keyPath: KeyPath, json: JSON) + case notFoundKeyPath(keyPath: KeyPath & Sendable, json: JSON) case notFoundKey(key: String, json: JSON) case notFoundIndex(index: Int, json: JSON) - case failedToGetString(source: Any, json: JSON) - case failedToGetBool(source: Any, json: JSON) - case failedToGetNumber(source: Any, json: JSON) - case failedToGetArray(source: Any, json: JSON) - case failedToGetDictionary(source: Any, json: JSON) - case failedToParseURL(source: Any, json: JSON) - case decodeError(source: Any, json: JSON, decodeError: Error) + case failedToGetString(source: Any & Sendable, json: JSON) + case failedToGetBool(source: Any & Sendable, json: JSON) + case failedToGetNumber(source: Any & Sendable, json: JSON) + case failedToGetArray(source: Any & Sendable, json: JSON) + case failedToGetDictionary(source: Any & Sendable, json: JSON) + case failedToParseURL(source: Any & Sendable, json: JSON) + case decodeError(source: Any & Sendable, json: JSON, decodeError: Error) case failedToInitializeFromJSONString(String) case invalidJSONObject } @@ -49,7 +49,7 @@ public struct JSON: Hashable, @unchecked Sendable { public static let null = JSON() - public internal(set) var source: Any + public internal(set) var source: Any & Sendable fileprivate let breadcrumb: Breadcrumb? @@ -69,14 +69,14 @@ public struct JSON: Hashable, @unchecked Sendable { } public init(_ object: [String : JSON]) { - source = object.reduce(into: [String : Any]()) { (dictionary, object) in + source = object.reduce(into: [String : Any & Sendable]()) { (dictionary, object) in dictionary[object.key] = object.value.source } breadcrumb = nil } public init(_ object: [String : JSONWritableType]) { - source = object.reduce(into: [String : Any]()) { (dictionary, object) in + source = object.reduce(into: [String : Any & Sendable]()) { (dictionary, object) in dictionary[object.key] = object.value.jsonValueBox.source } breadcrumb = nil @@ -99,14 +99,14 @@ public struct JSON: Hashable, @unchecked Sendable { self.init(source: source, breadcrumb: nil) } - public init(any: Any) throws { + public init(any: Any & Sendable) throws { guard JSONSerialization.isValidJSONObject(any) else { throw JSONError.invalidJSONObject } self.init(source: any, breadcrumb: nil) } - init(source: Any, breadcrumb: Breadcrumb?) { + init(source: Any & Sendable, breadcrumb: Breadcrumb?) { self.source = source self.breadcrumb = breadcrumb } @@ -162,12 +162,12 @@ extension JSON { extension JSON { - fileprivate mutating func set(any: Any?, for key: String) { + fileprivate mutating func set(any: (Any & Sendable)?, for key: String) { if source is NSNull { - source = [String : Any]() + source = [String : Any & Sendable]() } - guard var dictionary = source as? [String : Any] else { + guard var dictionary = source as? [String : Any & Sendable] else { return } dictionary[key] = any diff --git a/Sources/JAYSON/JSONWritableType.swift b/Sources/JAYSON/JSONWritableType.swift index 51498b4..68a57e2 100644 --- a/Sources/JAYSON/JSONWritableType.swift +++ b/Sources/JAYSON/JSONWritableType.swift @@ -24,7 +24,7 @@ import Foundation public struct JSONValueBox { - public let source: Any + public let source: Any & Sendable public init(_ object: NSNull) { self.source = object @@ -59,7 +59,7 @@ public struct JSONValueBox { } } -public protocol JSONWritableType { +public protocol JSONWritableType: Sendable { var jsonValueBox: JSONValueBox { get } } @@ -76,6 +76,7 @@ extension String: JSONWritableType { } } +extension NSString: @retroactive @unchecked Sendable {} extension NSString: JSONWritableType { public var jsonValueBox: JSONValueBox { return JSONValueBox(self) From 85fb1d43dde19f26c89143308f6c85a08b3c6e82 Mon Sep 17 00:00:00 2001 From: Muukii Date: Fri, 20 Sep 2024 22:39:34 +0900 Subject: [PATCH 2/2] WIP --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index a8ecfe8..227e258 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription let package = Package(