Refactor ReadResult decoding for Swift 6#735
Merged
mickael-menu merged 3 commits intodevelopfrom Feb 24, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the ReadResult decoding API for Swift 6 compatibility by splitting async reading from synchronous decoding operations. The refactoring addresses Swift 6's stricter concurrency requirements by avoiding crossing isolation contexts with non-Sendable types like [String: Any].
Changes:
- Split
Streamable.readAsX()async functions into separateread()(async) andasX()(synchronous) methods onReadResult<Data>andReadResult<Data?> - Made XML parsing methods synchronous (except for file I/O in
open(file:)which usesTask.detached) - Added comprehensive tests for the new
ReadResultdecoding API using Swift Testing framework - Updated all call sites across the codebase to use the new
read().asX()pattern - Deprecated the old
readAsX()methods with migration guidance
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
Tests/SharedTests/Toolkit/Data/ReadResultTests.swift |
New comprehensive test suite for ReadResult decoding methods using Swift Testing framework |
Tests/SharedTests/Publication/Services/Positions/PositionsServiceTests.swift |
Updated to use read().asString() pattern |
Tests/SharedTests/Publication/PublicationTests.swift |
Updated to use read().asString() pattern |
Sources/Streamer/Parser/Readium/ReadiumWebPubParser.swift |
Refactored to use read().asRWPM() pattern, moved extension from Streamable to ReadResult<Data> |
Sources/Streamer/Parser/Readium/ReadiumGuidedNavigationService.swift |
Updated to use read().asJSONObject() pattern |
Sources/Shared/Toolkit/XML/XML.swift |
Made open(data:) and open(string:) synchronous; open(file:) uses Task.detached for async I/O |
Sources/Shared/Toolkit/Format/Sniffers/RPFFormatSniffer.swift |
Updated to use read().asJSONObject() pattern |
Sources/Shared/Toolkit/Format/Sniffers/EPUBFormatSniffer.swift |
Updated to use read().asString() pattern and removed await from synchronous XML parsing |
Sources/Shared/Toolkit/Format/FormatSnifferBlob.swift |
Removed await from synchronous XML parsing call |
Sources/Shared/Toolkit/Data/Streamable.swift |
Deprecated readAsString(), readAsJSON(), and readAsJSONObject() with migration messages |
Sources/Shared/Toolkit/Data/Resource/ResourceContentExtractor.swift |
Updated to use read().asString() and made XML parsing synchronous |
Sources/Shared/Toolkit/Data/ReadResult.swift |
New file with decode(), asString(), asJSON(), asJSONObject(), and asXML() methods for both ReadResult<Data> and ReadResult<Data?> |
Sources/Shared/Toolkit/Data/ReadError.swift |
Moved ReadResult typealias to ReadResult.swift |
Sources/Shared/Publication/Services/Positions/PositionsService.swift |
Updated to use read().asJSONObject() pattern |
Sources/Shared/Publication/Services/Content/Iterators/HTMLResourceContentIterator.swift |
Updated to use read().asString() pattern |
Sources/LCP/Toolkit/ReadResult.swift |
Refactored readAsLCPL() from Streamable extension to asLCPL() on ReadResult<Data> |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Splits the
Streamable.readAsX()async functions into an asyncread()and synchronousasX()functions. This is to avoid crossing isolation contexts with non sendable objects such as[String: Any].