0

I'm trying to combine a string and a variable into a variable to use in a API request.

Here is the code I am using:

let urlString = ("example.com/api/balance/", addr)
guard let url = URL(string: urlString) else { return }

The variable urlString needs to be set to example.com/api/balance/addr

Xcode 9 is giving me the error Cannot convert value of type '(String, String)' to expected argument type 'String'

How would I make the string and the variable into one string?

I am using Xcode 9 with Swift4

5
  • try this: let urlString = "example.com/api/balance/" + "addr" Commented Nov 16, 2017 at 3:17
  • addr is an variable so adding quotes to it won't work because it will turn it into a string. Commented Nov 16, 2017 at 3:19
  • yes but he said he wants the result to be example.com/api/balance/addr and what I posted returns that result. if addr is a variable of type string then it would be let urlString = "example.com/api/balance/" + addr Commented Nov 16, 2017 at 3:20
  • let urlString = "example.com/api/balance/(addr)" Commented Nov 16, 2017 at 3:22
  • Please spend time reading the Swift Programming Language book. Specifically, for this question, the section on String Interpolation Commented Nov 16, 2017 at 3:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.