URL - leacode/SwiftWings GitHub Wiki
Sources
Sources/Extensions/Foundation/URL/URL+Query.swift
Tests: Tests/Extensions/URL
SwiftWings draws inspiration from community write-ups on URLComponents best practices and helper collections such as SwifterSwift when crafting its URL helpers. Key resources include:
- SwifterSwift URLExtensions – demonstrates coalescing query parameters and builder-style APIs.
| API | Description | Tests |
|---|---|---|
URL.queryParameters |
Returns [String: String] while coalescing duplicate keys similar to SwifterSwift's implementation. |
URL_QueryTests.testQueryParametersCoalescesDuplicates |
URL.mergingQueryParameters(_:replaceExisting:) |
Inspired by blog discussions on URLComponents merges and SwifterSwift's appendingQueryParameters; merges/removes keys in one builder call. |
URL_QueryTests.testMergingQueryParametersReplacingValues, URL_QueryTests.testMergingQueryParametersSkippingExistingWhenRequested
|
URL.removingQueryParameters(_:) |
Convenience wrapper that translates sequences into removal operations for mergingQueryParameters. |
URL_QueryTests.testRemovingQueryParameters |
var profile = URL(string: "https://example.com/profile?tab=posts")!
let filtered = profile.mergingQueryParameters([
"tab": "about",
"filter": "recent"
])
let clean = filtered?.removingQueryParameters(["filter"]) // https://example.com/profile?tab=about