I am running into a problem that causes my app to crash trying to update the contents of a label on the Viewcontroller. Here is my code below.
if numberOfLoops < numberOfLoopsReq {
// delay before and play
counter?.increment()
//getCounterValue()
dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue),0)) {
ViewController().self.numberOfLoopsExecuted.text = self.counter?.count.description
dispatch_async(dispatch_get_main_queue()) {
//do nothing here
}
}
let delayMp3 = (GlobalVariables.DelayBeforeSong + GlobalVariables.DelayAfterSong) * Double(NSEC_PER_SEC)// nanoseconds per second
let delayTimePlayer = dispatch_time(DISPATCH_TIME_NOW, Int64(delayMp3))
dispatch_after(delayTimePlayer, dispatch_get_main_queue(),{
self.player!.play()
})
numberOfLoops = GlobalVariables.NumberOfLoops
}
The call that causes the crash is the call to is the:
ViewController().self.numberOfLoopsExecuted.text = self.counter?.count.description