Skip to content

Conversation

@maatheusgois-dd
Copy link
Contributor

@maatheusgois-dd maatheusgois-dd commented Sep 3, 2025

Summary

This PR addresses Swift Concurrency compilation errors and unused return value warnings that were preventing successful builds with Swift 5.9+ strict concurrency checking enabled.

Changes Made

1. Fixed Sendable Closure Error in WKWebViewNetworkMonitor.swift

Problem: [String: Any] is not Sendable, causing compilation failure when captured in @Sendable closures.

Solution:

  • Created WebViewRequestInfo struct that conforms to Sendable
  • Implemented proper type-safe data storage with Sendable types:
    • String for request ID, URL, method, body
    • Date for timing information
    • [String: String] for headers
  • Maintained API compatibility through toDictionary() and from initializer
  • Updated WebViewRequestCache to use the new Sendable struct internally

Files Modified: DebugSwift/Sources/Features/Network/Helpers/WKWebViewNetworkMonitor.swift

2. Fixed Unused Return Value Warnings in Network.ViewModel.swift

Problem: Return values from addHttpRequest calls were unused, generating compiler warnings.

Solution:

  • Added _ = prefix to explicitly discard return values
  • This occurs in the handleClearAction method when re-adding requests after clearing operations

Files Modified: DebugSwift/Sources/Features/Network/Main/Network.ViewModel.swift

Technical Details

Swift Concurrency Fix

The core issue was that [String: Any] cannot be captured in @Sendable closures because Any can contain non-Sendable types. The solution provides:

  1. Type Safety: All stored data is now explicitly typed as Sendable types
  2. Data Conversion: Proper handling of various body data types (String, Dictionary, etc.) to Sendable equivalents
  3. API Compatibility: Existing code continues to work without changes
  4. Performance: Clean data structure without unnecessary overhead

Compiler Warning Fix

The unused return value warnings were addressed by explicitly discarding the boolean return values from addHttpRequest calls, which indicate whether the request was successfully added to the datasource.

Testing

  • ✅ Project builds successfully with Swift Concurrency enabled
  • ✅ All linter warnings resolved
  • ✅ No functional changes to existing behavior
  • ✅ Backward compatibility maintained

Impact

  • Build Success: Resolves compilation failures with modern Swift versions
  • Code Quality: Eliminates compiler warnings
  • Future-Proof: Ensures compatibility with Swift 6 when strict concurrency becomes mandatory
  • Maintainability: Cleaner, more type-safe code structure

Breaking Changes

None. All changes are backward compatible.


Labels: bugfix, swift-concurrency, compiler-warnings, network-monitoring

@maatheusgois-dd maatheusgois-dd added the Bugfix Problems without priority. label Sep 3, 2025
@maatheusgois-dd maatheusgois-dd self-assigned this Sep 3, 2025
@maatheusgois-dd maatheusgois-dd changed the title [Bugfix] Sendable Error Fix Swift Concurrency Issues and Compiler Warnings Sep 3, 2025
@maatheusgois-dd maatheusgois-dd marked this pull request as ready for review September 3, 2025 01:35
@github-actions
Copy link

github-actions bot commented Sep 3, 2025

Warnings
⚠️

The PR title should be: [Feature or Flow] What flow was done

Messages
📖 Project coverage: 14.5%
📖 The PR added 55 and removed 7 lines. 2 file(s) changed.

DebugSwift: Coverage: 10.33

File Coverage
Network.ViewModel.swift 9.64% ⚠️
WKWebViewNetworkMonitor.swift 3.79% ⚠️

Generated by 🚫 Danger Swift against 62b3d7d

@maatheusgois-dd maatheusgois-dd merged commit 7c141b2 into main Sep 3, 2025
5 checks passed
@maatheusgois-dd maatheusgois-dd deleted the bugfix/sendable-error branch September 3, 2025 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugfix Problems without priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Capture of non-Sendable type '[String: Any]' in @Sendable closure (WKWebViewNetworkMonitor.swift)

2 participants