Swift 6.2 Approachable Concurrency Migration for NetworkKit#6
Open
sabapathy7 wants to merge 8 commits intomainfrom
Open
Swift 6.2 Approachable Concurrency Migration for NetworkKit#6sabapathy7 wants to merge 8 commits intomainfrom
sabapathy7 wants to merge 8 commits intomainfrom
Conversation
With InternalImportsByDefault experimental feature enabled in Swift 6.2, imports are treated as internal by default. This caused compilation errors when public API methods used URLSessionConfiguration and AnyPublisher types. Changed to @_exported import to ensure these types remain accessible to consumers of the NetworkKit public API.
Added Sendable conformance to all data model types for Swift 6 concurrency: - EndPoint protocol: Sendable conformance with documentation - NetworkError enum: Sendable conformance with documentation - RequestMethod enum: Sendable conformance with documentation Additional improvements: - NetworkError: Changed 'default' to explicit 'case .unknown' (exhaustive) - RequestMethod: Standardized 'PATCH' to lowercase 'patch' (Swift naming) These changes ensure all data types can be safely shared across concurrency domains without data races. Related: Swift 6 strict concurrency checking
Refactored NetworkService for Swift 6 concurrency safety: - Added @unchecked Sendable conformance (verified thread-safe) - Replaced URLSession.shared with immutable instance property - Added init(configuration:) and convenience init() - Enables dependency injection for testing Benefits: - No shared global state - Thread-safe by design (immutable properties) - Testable via URLSessionConfiguration injection - Proper initialization patterns Related: Swift 6 strict concurrency, dependency injection
Multiple improvements to NetworkService implementation: Error Handling: - Replaced try? with proper do-catch blocks - Changed preconditionFailure to Fail publisher (Combine) - Fixed incorrect error types (.invalidURL -> .unexpectedStatusCode) - Better variable naming (response -> httpResponse) Code Organization: - Converted extension to private methods - Added comprehensive documentation - Added MARK comments for navigation - Removed empty public init() These changes improve maintainability and prevent runtime crashes. Breaking: Combine method returns Fail instead of crashing.
Repository owner
locked as off-topic and limited conversation to collaborators
Dec 27, 2025
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
📋 Summary
This PR migrates NetworkKit to Swift 6.2 with Approachable Concurrency support, enabling strict concurrency checking while maintaining full backward compatibility with all existing API patterns (async/await, Combine, closures).
🎯 Motivation
Adopt Swift 6.2's "Approachable Concurrency" features (SE-0461)
Enable strict concurrency checking for data-race safety
Demonstrate modern Swift concurrency patterns
Prepare codebase for conference talk on Swift 6.2 concurrency
🔧 Changes Made
Updated swift-tools-version from 5.8 to 6.0
Enabled StrictConcurrency feature flag
Enabled ApproachableConcurrency feature flag (Swift 6.2)
Enabled InternalImportsByDefault experimental feature
Applied concurrency features to both main and test targets
EndPoint: Added Sendable conformance with documentation
NetworkError: Added Sendable conformance, fixed default → explicit case .unknown
RequestMethod: Added Sendable conformance, standardized PATCH → patch naming
Added Sendable protocol conformance
Added Sendable constraints to all generic type parameters (T: Decodable & Sendable)
Enhanced documentation with SE-0461 isolation context notes
Added sendRequestWithContinuation method to demonstrate bridging pattern
Organized methods with clear MARK comments by pattern type
Thread-Safety Improvements
Added @unchecked Sendable conformance (manually verified safe)
Replaced URLSession.shared with immutable instance property
Added dependency injection via init(configuration:)
Added convenience init() for default configuration
Error Handling Improvements
Replaced try? with proper do-catch blocks for better error propagation
Fixed preconditionFailure in Combine method → returns Fail publisher
Improved variable naming (avoided shadowing: response → httpResponse)
Corrected error types (.invalidURL → .unexpectedStatusCode where appropriate)
Code Organization
Converted extension methods to private methods
Changed fileprivate → private for better encapsulation
Added comprehensive method documentation
Added MARK comments for code navigation