Gonzo Loopback
Gonzo Loopback

Reputation: 17

Concatenate URL text from UITextField to global variable NSURL

I have a variable httpUrl in my rootViewController that all the other ViewControllers inherit from.

var httpUrl = NSURL(string: "http://")

In another ViewController I have an UITextField @IBAction that I want the user's input and then add it to the var httpUrl.

@IBAction func urlTextField(sender: AnyObject) {

    //NSURL(string: self.urlTextField.text)

}

Upvotes: 0

Views: 1150

Answers (1)

Atomix
Atomix

Reputation: 13842

The easiest way to do this is probably to create a string of the desired format and then turn it into an URL, since there isn't really a way to concatenate two URLs.

let urlString = "http://\(urlTextField.text)"
let combinedUrl = NSURL(string: urlString)

Upvotes: 1

Related Questions