If I create a URL like this:
guard var urlComponents = URLComponents(url: "https://example.com/something", resolvingAgainstBaseURL: false) else {
return
}
let queryItems = URLQueryItem(name: "token", value: token)
urlComponents.queryItems = [queryItems]
guard let urlWithQueryItem = urlComponents.url else {
return
}
I want the end result to be something like https://example.com/something#token=7as78f6asd678768asd768asd678
Instead of the default https://example.com/something?token=7as78f6asd678768asd768asd678
(I'm looking for something smarter than a search and replace of the ? character)
Thanks
As others have noted, URLQueryItem object is more intended for use with querystrings vs anchors/fragments. With that said, below is a function that helps you accomplish what your questions is asking.
Here is a link to a working Swift fiddle of the code. http://play.swiftengine.io/code/8JKI3/2