Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete parameter from URL with swift

Tags:

string

url

swift

I have an URL that looks like myapp://jhb/test/deeplink/url?id=4567 . I want to delete every thing after the ? char. At the end the URL should look like myapp://jhb/test/deeplink/url. how. can I achieve that? convert the url to a string? Regex?

like image 473
doej Avatar asked Oct 09 '17 12:10

doej


1 Answers

Use URLComponents to separate the different URL parts, manipulate them and then extract the new url:

var components = URLComponents(string: "myapp://jhb/test/deeplink/url?id=4567")!
components.query = nil
print(components.url!)

myapp://jhb/test/deeplink/url

like image 174
luk2302 Avatar answered Sep 22 '22 23:09

luk2302