Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialChapin Alf
Courses Plus Student 138 PointsGetting error "Use of unresolved identifier 'urlContents'.
Copy of code: class ViewController: UIViewController {
private let apiKey = "00bd1d14e13bd044bdb542e26303873d"
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let baseUrl = NSURL(string:"https://api.forecast.io/forecast/\(apiKey)/")
let forecastUrl = NSURL(string: "26.361857,-80.071547", relativeToURL: baseUrl)
let sharedSession = NSURLSession.sharedSession()
let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastUrl!, completionHandler: { (location: NSURL!, response: NSURLResponse!, error: NSError!) -> Void in
NSString(contentsOfURL: location, encoding: NSUTF8StringEncoding, error: nil)
println(urlContents)
})
downloadTask.resume()
2 Answers
Rolando Cruz
2,995 PointsHi Chapin!
I noticed right here, that you didn't store this block of code in a constant:
NSString(contentsOfURL: location, encoding: NSUTF8StringEncoding, error: nil)
println(urlContents)
So instead, it should look something like this:
let urlContents = NSString(contentsOfURL: location, encoding: NSUTF8StringEncoding, error: nil)
println(urlContents)
Greg Kaleka
39,021 PointsHi Chapin,
You're trying to println
urlContents, which you haven't defined as a constant or variable. What are you trying to print, exactly?
Greg Kaleka
39,021 PointsGreg Kaleka
39,021 PointsHey Ronaldo - just an FYI that I cleaned up your formatting a bit.