Although Swift is not a common language for server backends, but it can also parse URLs. Just in case, I still did some research.
Assuming the URL being parsed is: https://www.example.com/?keyword=abc
. Code as below:
import UIKit
// Convert the URL string into a URL type constant (variables are fine)
let url = URL(string: "https://www.example.com/?keyword=abc")
// Output the query part (best not use an exclamation mark here to force it to "yes" to prevent errors)
print(url?.query ?? "No query")
Output:
keyword=abc
I hope these will help someone in need~