I have a table of products and each has a download button. Each button is its own NSTableCellView in a separate class. I want to disable/hide a button in the original Product View Controller class if a download is in progress. But whenever I try to do that my app crashes with very little error messaging as to why. Is there anyway to accomplish my goal?
let viewCon = ProductViewController()
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {
let filesize: Int64 = Int64(passedLongBytes)!
let percentage = CGFloat(totalBytesWritten) / CGFloat(filesize)
DispatchQueue.main.async{
self.shapeLayer.strokeEnd = percentage
print("PERCENTAGE: \(Int(percentage * 100))%")
if((Int(percentage * 100) < 100)){
self.viewCon.backButtonOutlet.isHidden = true
}else{
self.viewCon.backButtonOutlet.isHidden = false
}
}
}
I just get an error message everything "Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)"
So I cam up with an alternate solution where I created a global Int variable that checks the percentage and then I can use that global variable in my other ProductViewController. I don't know if this is the best way to do it but it seems to have achieved my goal.
CellView
ProductviewController