Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

499
Views
How to encode url string properly to avoid question mark (?) from being %3F in swift?

I'm sending a request to server using Alamofire pod.

var urlComponents = URLComponents(string: "/hotel/v2")!
urlComponents.queryItems = [
     URLQueryItem(name: "page", value: page)
]
let urlString = urlComponents.url?.absoluteString
var urlRequest = URLRequest(url: url.appendingPathComponent(urlString))

The problem begins when I print out the urlRequest. It shows as : enter image description here

Then the request reach the backend and the backend returns me some error.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Don't use url.appendingPathComponent. You have created a URLComponents. Use it properly.

var urlComponents = URLComponents(string: url)!
urlComponents.path = "/hotel/v2"
urlComponents.queryItems = [
     URLQueryItem(name: "page", value: page)
]
var urlRequest = URLRequest(url: urlComponents.url!)

Here I am assuming that url is something like "https://somedomain.com".

over 4 years ago · Santiago Trujillo Report

0

You can simply do this - Swift 4 & 5

let url = URL(string: APIServant.API_DEV_URL + path)!
var urlRequest = URLRequest(url: url)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!