Skip to content

Conversation

@lex00
Copy link

@lex00 lex00 commented Jan 26, 2026

Summary

Add Swift 6 support with full Sendable conformance for the JSON type, addressing #1163.

Changes

  • Package.swift: Update to swift-tools-version:6.0, remove swiftLanguageVersions lock
  • JSON struct: Add @unchecked Sendable conformance
  • Type enum: Add Sendable conformance
  • SwiftyJSONError enum: Add Sendable conformance
  • JSONKey enum: Add Sendable conformance
  • Tests: Add 3 focused concurrency tests
  • Docs: Update README requirements and CHANGELOG

Why @unchecked Sendable?

The JSON struct stores values in [Any] and [String: Any] properties, which the compiler cannot verify as Sendable. However, @unchecked Sendable is safe because:

  1. JSON is a value type with value semantics
  2. Internal storage only contains Sendable types (String, NSNumber, NSNull, nested JSON)
  3. Copy-on-write ensures no shared mutable state

Testing

  • All 146 existing tests pass
  • Added 3 focused concurrency tests, each verifying a specific Sendable conformance:
    • testJSONSendable: JSON crosses actor boundary
    • testTypeSendable: Type enum crosses actor boundary
    • testSwiftyJSONErrorSendable: SwiftyJSONError crosses actor boundary

Total: 149 tests passing with zero warnings.

Checklist

  • Tests pass locally
  • No compiler warnings
  • Documentation updated (README, CHANGELOG)
  • Backwards compatible (no breaking API changes)

Closes #1163

- Update Package.swift to swift-tools-version:6.0
- Remove swiftLanguageVersions lock
- Add @unchecked Sendable to JSON struct
- Add Sendable to Type, SwiftyJSONError, JSONKey enums
- Add comprehensive concurrency tests (18 tests)
- Update README requirements and CHANGELOG

The JSON type can now safely cross actor boundaries in Swift 6 concurrency.

Closes SwiftyJSON#1163
Each test now directly corresponds to a type made Sendable:
- testJSONSendable: JSON crosses actor boundary
- testTypeSendable: Type enum crosses actor boundary
- testSwiftyJSONErrorSendable: SwiftyJSONError crosses actor boundary

Removed redundant tests that proved the same thing in different ways
(TaskGroup, Task.detached, MainActor variations).

Added missing coverage for Type enum Sendable conformance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON is not Sendable. Does it plan to migrate to Swift 6? Is this project still in maintenance?

1 participant