I have the URL to there I send my requests to get the results:
let URL = "https://api.myweb.site/search/\(searchText)"
but when my searchText contains a placeholder letter my app crashes. By the way, I'm using Alamofire.
How can I make my URL safe and avoid the crash? I've tried this:
let escapedString = searchText.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!
but it crashes again. What is the solution for my problem?
The solution is:
let newURL:String = oldURL.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!