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

Hamish
  • 78,605
  • 19
  • 187
  • 280
Matthew N
  • 359
  • 4
  • 14
  • try this: `let urlString = "example.com/api/balance/" + "addr"` – Nevin Jethmalani Nov 16 '17 at 03:17
  • addr is an variable so adding quotes to it won't work because it will turn it into a string. – Matthew N Nov 16 '17 at 03: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` – Nevin Jethmalani Nov 16 '17 at 03:20
  • let urlString = "example.com/api/balance/\(addr)" –  Nov 16 '17 at 03:22
  • Please spend time reading the [Swift Programming Language](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/) book. Specifically, for this question, the section on [String Interpolation](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html#//apple_ref/doc/uid/TP40014097-CH7-ID292) – rmaddy Nov 16 '17 at 03:26

0 Answers0