URL encode in swift

 let urlString = "Write your url string"
 let url = URL(string: urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)!
 print(url)
 var request = URLRequest(url: url)