Wednesday, October 28, 2026
HomeiOS Developmentios - Learn how to repair URLQueryItem in swift

ios – Learn how to repair URLQueryItem in swift

[ad_1]

Don’t percent-encode the worth you provide to URLQueryItem. URLQueryItem does that for you. As it’s, you might be double percent-encoding it (i.e., it’s percent-encoding the % of your percent-encoded string).

So, as a substitute, merely provide the straightforward string, and let URLComponents maintain it:

let queryItem = URLQueryItem(identify: "scope", worth: "channel:handle:polls+channel:learn:polls")

As an apart, the : characters don’t should be % encoded when encountered inside a question, anyway. E.g.:

let queryItem = URLQueryItem(identify: "scope", worth: "channel:handle:polls+channel:learn:polls")

var parts = URLComponents(string: "https://instance.com")
parts?.queryItems = [
    queryItem
]

guard let url = parts?.url else { return }

print(url) // https://instance.com?scope=channel:handle:polls+channel:learn:polls

(See RFC3986.)

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments