我有一个操作队列设置如下:
let queue = OperationQueue()
queue.name = "com.company.myQueue"
queue.qualityOfService = .userInitiated
queue.maxConcurrentOperationCount = 64
...
var current = 0
var totalCount = someArray.count
for i in someArray {
...
let op = BlockOperation {
... // do some database queries
current += 1
}
op.completionBlock = {
DispatchQueue.main.async {
let nData: [String: CGFloat] = ["value": CGFloat(current/totalCount)]
NotificationCenter.default.post(name:Notification.Name(rawValue: "update"), object: nil, userInfo: nData)
}
queue.addOperation(op)
}
在我的ViewController
我收听通知并UILabel
用百分比更新 a。问题是虽然我没有得到任何中间值......它从0
直接跳转到100
所有操作完成后。
我究竟做错了什么?
谢谢