Alright, so just to start off, heres my code:
import UIKit
import ForecastIO
class Weather {
var temp: Float
var condition: String
var wind: Fl
I'd hazard to guess that your are running into a concurrency problem. You are probably trying to access your object's properties before the asynchronous call to the DarkSkyClient returns (my apologies in advance if I got this wrong). i.e., the order of events is...
So what you really need to do is switch to an inversion of control pattern:
class Weather {
var temp: Float
var condition: String
var wind: Float
var precip: Float
init(forecast: Forecast) {
temp = (forecast.currently?.temperature)!
condition = (forecast.currently?.summary)!
wind = (forecast.currently?.windSpeed)!
precip = (forecast.currently?.precipitationProbability)!
}
static func getWeather() {
DarkSkyClient(apiKey: "").getForecast(latitude: Utils().getLat(), longitude: Utils().getLong()) { result in
switch result {
case .success(let currentForecast, _):
let weather = Weather(forecast: currentForecast)
// Display the weather somewhere
doSomethingWith(weather: weather)
case .failure(let error):
print(error)
}
}
}
}
If you're not familiar with developing with asynchronous APIs it's worth your while to read up on the subject; it can be very tricky (sadly, I don't have any recommendations for a good primer). Hope this helps!