- URLUtils contains a property
queryParams
implemented in Objective-C and apparently is NOT available in Swift onURL
types but only onNSURL
type. This looks odd to me because when declaring the same category in an App and using the bridging header file, thenqueryParams
is also usable fromURL
type too.
Is this the expected behaviour for SPM packages containing Objective-C code?
// Swift file.
import URLUtils
func testURL() throws { // Problem: Testing with URL does NOT compile (With NSURL is compiles OK)
let url = URL(string: "https://domain.com/path?a=123")!
let queryParams = url.queryParams // error: value of type 'URL' has no member 'queryParams'
}
Run swift test
.
I asked the same question:
- Stackoverflow - SPM library with Objective-C NSURL category not imported into Swift URL?
- SwiftForums - Why SPM library with Objective-C NSURL category is not available in Swift URL type?
Solution explanation: NSURL and URL and not the same type and the compiler does the magic that makes them look like same, it is implemented using ReferenceConvertible. I think that only happens for types inside Foundation and/or App module. However if I create my own frameworks/library it will be a different module, different compiling time. Hence, I will not get the same benefits so I need to explicitly create a target for Swift too.
Problem solved in this Pull Request.