Search code examples
iosswiftalamofire

Why is involving a special character from another language creating a crash when I try to call api in iOS SWIFT?


This is the culprit string and paramter name=solsssㅗ

 Alamofire.request(todoEndpoint)
            .responseJSON { response in
                // check for errors
                guard response.result.error == nil else {
                    // got an error in getting the data, need to handle it
                    print("error calling GET on \(todoEndpoint)")
                    print(response.result.error!)
                    DispatchQueue.main.async
                        {
                            self.activityView.isHidden = true
                            self.activityView.stopAnimating()
                    }
                    return
                }

So I get error in URL always as invalid. If I use it without any special character it works fine.


Solution

  • You can try this with String url -

    let urlWithSpecialCharacter = url.addingPercentEncoding( withAllowedCharacters: .urlQueryAllowed)