0

I am trying to create an URL something like it https://api.website.com/products?product_ids=1,2,3,4,5 Using integer array from CoreData

So far I do have this code

let array = [1,2,3,4,5]

var urlComponents = URLComponents()
urlComponents.scheme = "https"
urlComponents.host = "api.website.com"
urlComponents.path = "/products"
urlComponents.queryItems = [
    URLQueryItem(name: "product_ids", value: ???????),
]

How can I add my array data to get a full URL I needed? https://api.website.com/products?product_ids=1,2,3,4,5

1

1 Answer 1

5

You just need to map your array elements into a string and join the result using a comma:

let value = array.map(String.init).joined(separator: ",")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.