-
Notifications
You must be signed in to change notification settings - Fork 749
Closed as not planned
Closed as not planned
Copy link
Labels
questionIssues that have a question which should be addressedIssues that have a question which should be addressed
Description
Question
extension MySchema {
public enum CustomJSON: CustomScalarType, Hashable {
case dictionary([String: AnyHashable])
case array([AnyHashable])
public init(_jsonValue value: JSONValue) throws {
if let dict = value as? [String: AnyHashable] {
self = .dictionary(dict)
} else if let array = value as? [AnyHashable] {
self = .array(array)
} else {
throw JSONDecodingError.couldNotConvert(value: value, to: CustomJSON.self)
}
}
public var _jsonValue: JSONValue {
switch self {
case let .dictionary(json as AnyHashable),
let .array(json as AnyHashable):
return json
}
}
public static func == (lhs: CustomJSON, rhs: CustomJSON) -> Bool {
lhs._jsonValue == rhs._jsonValue
}
public func hash(into hasher: inout Hasher) {
hasher.combine(_jsonValue)
}
}
}
CustomScalarType & JSONValue now requires conforming types to be Sendable, and AnyHashable cannot conform to Sendable.
This makes the documented example unusable in practice. A note or an updated example using a Sendable-compatible type would be very helpful.
Metadata
Metadata
Assignees
Labels
questionIssues that have a question which should be addressedIssues that have a question which should be addressed