-4

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?

brimstone
  • 3,370
  • 3
  • 28
  • 49
temre
  • 189
  • 1
  • 3
  • 15

1 Answers1

1

To Concat strings in swift you have two options:

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

let completeURL = "http://blablabla.com/" + usernameVar + "&" + passwordVar
Ghulam Ali
  • 1,935
  • 14
  • 15
  • 2
    Note that convention states that variable names should start with a lowercase letter, and follow `camelCase`. For example, `completeURL` & `usernameVar` (although just `username` would be better) – Hamish May 04 '16 at 21:43
  • Thanks, I updated the answer. – Ghulam Ali May 04 '16 at 21:57