Instance Method
query(percentEncoded:)
iOS 16.0+
iPadOS 16.0+
Mac Catalyst 16.0+
macOS 13.0+
tvOS 16.0+
watchOS 9.0+
Returns the query component of the URL, optionally removing any percent-encoding.
func query(percentEncoded: Bool = true) -> String?
Parameters
percentEncodedWhether the query should be percent encoded, defaults to
true.
Return Value
The query component of the URL.
Discussion
The system doesn’t allow certain characters in the URL query component, so URL percent-encodes those characters to create a valid URL. Calling this function with percentEncoded = false removes any percent-encoding and returns the unencoded query.
If the URL doesn’t contain a query component according to RFC 3986, this function returns nil.