Make Query URL using swift 3

Some times we need to extract some data or get the specific key data from URL. In order to achieve that we need to break the whole url string in “&” and we have to store data as  array in a variable. After that we have to make search so doing this , is taking more time and more complexity. The post will show a simple and easy way to Make Query URL using swift 3.

So let’s get started,

here is an example url: http://www.example.com?foo=bar&foo2=bar2

the url params are foo and foo2

We are going to use URLComponents method as it provides us the better way to handle the  query on URL.

Here queryItems contains all params data therefore we are doing the query on this params and filtering by name so foo will provide the respected value “bar”