Skip to content

Commit

Permalink
Swift 6 Sendable stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rudrankriyam committed Nov 13, 2024
1 parent 17760fe commit ba4c537
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Sources/SakuraKit/Play/PlayAI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,25 @@ private extension Data {
}

private extension JSONDecoder {
/// A JSON decoder configured to handle Play API date formats.
/// Uses ISO8601 format with internet date time and fractional seconds.
static var playDateDecoder: JSONDecoder {
let decoder = JSONDecoder()

// Create formatter outside closure to avoid Sendable capture
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]

// Use @Sendable closure that doesn't capture formatter
decoder.dateDecodingStrategy = .custom { decoder in
let container = try decoder.singleValueContainer()
let dateStr = try container.decode(String.self)

guard let date = formatter.date(from: dateStr) else {
// Create new formatter inside closure instead of capturing
let localFormatter = ISO8601DateFormatter()
localFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]

guard let date = localFormatter.date(from: dateStr) else {
throw DecodingError.dataCorruptedError(
in: container,
debugDescription: "Invalid date format: \(dateStr)"
Expand Down

0 comments on commit ba4c537

Please sign in to comment.