Mr E Mr E - 7 months ago 28
Swift Question

How to concatenate strings in Swift

I am trying to get USERNAME and PASSWORD from the user and put them inside of a string.

var id = "1"
var pw = "password"


Here is my code:

parser = NSXMLParser(contentsOfURL: NSURL(string : "http://blablabla.com/UNAME&PW")!)!


But it creates this result:

"http://blablabla.com/\id\&\pw\"


How do I put the values of
id
and
pw
inside of a string?

Answer

To Concat strings in swift you have two options:

let completeURL = "http://blablabla.com/\(usernameVar)&\(passwordVar)"

let completeURL = "http://blablabla.com/" + usernameVar + "&" + passwordVar
Comments