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 trialIngo Ngoyama
4,882 PointsI am not getting a print out of anything in the output window or I just get (11db.) in my output and no
I am not getting a print out of anything in the output window or I just get (11db.) in my output but none of the print statements ever print out
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var currentTemperatureLabel: UILabel!
@IBOutlet weak var currentHumidityLabel: UILabel!
@IBOutlet weak var currentPrecipitationLabel: UILabel!
@IBOutlet weak var currentWeatherIcon: UIImageView!
@IBOutlet weak var currentSummaryLabel: UILabel!
@IBOutlet weak var refreshButton: UIButton!
@IBOutlet weak var activityIndicator: UIActivityIndicatorView!
fileprivate let darkSkyApiKey = "d5ecc430de343cd643b8859b7a031d2a"//add key and give private protection(read in onenote)**********
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// after we set up our CurrentWeatherViewModel file **********
// now lets set up default dummy values **********
let currentWeather = CurrentWeather(temperature: 85.0, humidity: 0.8, precipitationProbability: 0.1, summary: "Hot !", icon: "clear-day")
let currentWeatherViewModel = CurrentWeatherViewModel(model: currentWeather)
displayWeather(using: currentWeatherViewModel) // now we can make an instance of displayWeather
//now we can call curentwweatherViewModel
//run and our dummy numbers should show
// add the DarkSky API url in a way that the location can be effiecintly changed *********
//note we used our stored prop var we made in our stored properties for the private key value. Quick typing *********
let base = URL(string: "https://api.darksky.net/forecast/\(darkSkyApiKey)/") // the constant part of URL *********
guard let forecastUrl = URL(string: "37.8267, -122.4233", relativeTo: base) else {return}//Use API URL to adjust location *********
// to creat a request(a few lines below) we must unwrap ForcastURL( which is an optional.)
// make an asynchrous network
let configuration = URLSessionConfiguration.default // config for our wtwkg needs *********
let session = URLSession(configuration: configuration) // create a session object to manage our network session *********
//Now using the above session object, we can create a task to carry out. *********
//The base class for this purpose is URLSession task, which defines a task during a session. *********
let request = URLRequest(url: forecastUrl) // use the subclass that ajust asks for a url to make a request *********
print("log before request on main thread")
//session.dataTask(with: request, completionHandler: .....//create a data task
let dataTask = session.dataTask( with: request) { data, response, error in print(" Log inside completion handler")} //change to a trailing closure ***
dataTask.resume() //*********
print("Log after resume")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func displayWeather(using viewModel: CurrentWeatherViewModel){ // display weather data through labels
currentTemperatureLabel.text = viewModel.temperature
currentHumidityLabel.text = viewModel.humidity
currentPrecipitationLabel.text = viewModel.precipitationProbability
currentSummaryLabel.text = viewModel.summary
currentWeatherIcon.image = viewModel.icon
// now create an instance above in viewDidLoad
}
}
Jeff McDivitt
23,970 PointsJeff McDivitt
23,970 PointsCan you share your code so I can see exactly what the issue is?