Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 6 #27

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions JAYSON.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
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.3
// swift-tools-version:6.0
import PackageDescription

let package = Package(
Expand Down
4 changes: 2 additions & 2 deletions Sources/JAYSON/JSON+OptionalProperty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ 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
}
}

public var array: [JSON]? {
return (source as? [Any])?
return (source as? [Any & Sendable])?
.enumerated()
.map {
JSON(
Expand Down
32 changes: 16 additions & 16 deletions Sources/JAYSON/JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
import Foundation

public enum JSONError: Error {
case notFoundKeyPath(keyPath: KeyPath<JSON, JSON?>, json: JSON)
case notFoundKeyPath(keyPath: KeyPath<JSON, JSON?> & 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
}
Expand All @@ -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?

Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions Sources/JAYSON/JSONWritableType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -59,7 +59,7 @@ public struct JSONValueBox {
}
}

public protocol JSONWritableType {
public protocol JSONWritableType: Sendable {

var jsonValueBox: JSONValueBox { get }
}
Expand All @@ -76,6 +76,7 @@ extension String: JSONWritableType {
}
}

extension NSString: @retroactive @unchecked Sendable {}
extension NSString: JSONWritableType {
public var jsonValueBox: JSONValueBox {
return JSONValueBox(self)
Expand Down
Loading