Whilst debugging I can see that the fixtureList in the controller returns 6 values. However, when the code jumps into the fixtureView.update(...)
within the View
, the fixtureList value is 0.
I'm sure it's something to do with creating the same variable in both controller and view, but can't figure it out!
What would be the best way to resolve this issue? Esentially I want the 6 values to be received by the View
so that the user interface can be populated.
Controller
var fixtureList = [Fixture]()
func updateScores() {
liveScoreApi.fetchFixtures() { (
isOK, fixture) in
if isOK == true {
for fixture in (fixture?.fixtures)! {
self.fixtureList.append(fixture)
}
self.fixtureView.update(/*dump*/(self.fixtureList))
}
else {
NSLog("error fetching!")
}
}
}
View
class FixtureView: NSView {
@IBOutlet weak var homeNameTextField: NSTextField!
@IBOutlet weak var timeTextField: NSTextField!
@IBOutlet weak var awayNameTextField: NSTextField!
let fixtureList = [Fixture]()
func update(_ fixture: [Fixture]) {
// do UI updates on the main thread
DispatchQueue.main.async {
for fixture in self.fixtureList {
self.homeNameTextField.stringValue = fixture.homeName
self.timeTextField.stringValue = fixture.time
self.awayNameTextField.stringValue = fixture.awayName
print("added \(fixture.homeName)")
}
}
}
}