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 trial

iOS Build a Weather App with Swift Interacting with Data From the Web Writing Concurrent Networking Code

Martin Foldyna
Martin Foldyna
10,359 Points

Nothing showing on my console. Can somebody help me?

When I run the app, the interface works. But my console is empty :(

Here is my code: import UIKit import Foundation

class ViewController: UIViewController { @IBOutlet weak var currentTemperatureLabel: UILabel? @IBOutlet weak var currentHumidityLabel: UILabel? @IBOutlet weak var currentPrecipitationLabel: UILabel?

private let forecastAPIKey = "ef27d42be089bd43da44bf6e5d3f0fee"


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/\(forecastAPIKey)/")
    let forecastURL = NSURL(string: "37.8267,-122.423", relativeToURL: baseURL)

    // Use NSURLSession API to fetch data
    let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
    let session = NSURLSession(configuration: configuration)

    //NSURLRequest object
    let request = NSURLRequest(URL: forecastURL!)


    let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
        print(data)
        print("I'm on background thread")
    })

    print("I'm on main thread")
    dataTask.resume()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

Darren Poole
Darren Poole
3,609 Points

Hi there, just had a quick look through your code, try the below for your dataTask property:

let dataTask = session.dataTaskWithRequest(request, completionHandler: {(data: NSData?, response:NSURLResponse?, error: NSError?) -> Void in print(data) })

I'm using Xcode 7.1 and Swift 2.1.

Hope it helps.