I'm trying to read data from a webpage and I'm using the NSString initialiser - init(contentsOfURL
since there's only one sentence on that page that I need to display in a label.
if var optUrl = NSURL(string: "www.example.com/examplepage.php"){
if let optStr = NSString(contentsOfURL: optUrl, encoding: NSUTF8StringEncoding, error: nil){
println(optStr)
songLabel.text = optStr
}
}
When I run the code in the emulator in Xcode, the println does print the sentence, but it won't show in the label... If I change the code to songLabel.text = "Now playing: \(optStr)"
, I get to see Now playing:
but not the value of optStr which is shown by the println.
Is there something I did wrong?