Reputation: 22691
I have a very simple NSViewController
, which hits an API using a WeatherFetcher
class. It passes a completion handler as a parameter, so that the HTTP API can call it once it finishes.
In this completion handler, I am trying to set the value of a simple NSTextField
to the result of API. However, I am getting this error:
Instance member 'currentTemp' cannot be used on type 'WeatherView'
Any idea what is wrong?
class WeatherView: NSViewController {
var weather:Weather?
@IBOutlet weak var currentTemp: NSTextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
WeatherFetcher.fetchCurrent(currentWeatherCallback)
}
override var nibName : String{
return "WeatherView"
}
var currentWeatherCallback =
{
(weather: Weather?) in
currentTemp.stringValue = weather?.updatedTime
// Instance member 'currentTemp' cannot be used on type 'WeatherView'
}
}
Upvotes: 0
Views: 2198
Reputation: 2156
You don't have access to the instance scope when initialising properties, you can only access the static context.
Try this:
var currentWeatherCallback: Weather? -> Void { return
{ (weather: Weather?) in
self.currentTemp.stringValue = weather?.updatedTime
}
}
Upvotes: 3