swift OS X 的进程指标
swift progessindicator for OS X
我有一个循环,它显示了我所有的地址簿联系人。
现在我想显示一个 NSProgressIndicator,它应该显示从 0(=开始请求联系人)到 100(=请求所有联系人)的进度。为此,我尝试了这样的事情:
let addressBook = ABAddressBook.shared()
let people = addressBook?.people()
for person in people! as! [ABPerson] {
print(person)
ProgressIndicator.increment(by: 0.22)
}
为什么增加 0.22?
我有 451 个联系人
100/451 = 每个联系人 0,22%
但是会发生什么?
我启动我的应用程序。打印结果将显示每个联系人,当请求所有联系人时 > 进度指示器直接跳到 100%。
我做错了什么?
第二次尝试:
DispatchQueue.global(qos: .background).async {
let addressBook = ABAddressBook.shared()
let people = addressBook?.people()
let stepPercent = 100 / (people?.count)!
for person in people! as! [ABPerson] {
print(person)
DispatchQueue.main.async {
self.ProgressIndicator.increment(by: Double(stepPercent))
}
}
我的解决方案:
DispatchQueue.global(qos: .background).async {
let addressBook = ABAddressBook.shared()
let people = addressBook?.people()
print(Double((people?.count)!))
let stepPercent = 100.00 / (Double((people?.count)!))
print(stepPercent)
for person in people! as! [ABPerson] {
print(person)
DispatchQueue.main.async {
self.ProgressIndicator.increment(by: Double(stepPercent))
}
}
感谢支持
我有一个循环,它显示了我所有的地址簿联系人。 现在我想显示一个 NSProgressIndicator,它应该显示从 0(=开始请求联系人)到 100(=请求所有联系人)的进度。为此,我尝试了这样的事情:
let addressBook = ABAddressBook.shared()
let people = addressBook?.people()
for person in people! as! [ABPerson] {
print(person)
ProgressIndicator.increment(by: 0.22)
}
为什么增加 0.22?
我有 451 个联系人 100/451 = 每个联系人 0,22%
但是会发生什么? 我启动我的应用程序。打印结果将显示每个联系人,当请求所有联系人时 > 进度指示器直接跳到 100%。
我做错了什么?
第二次尝试:
DispatchQueue.global(qos: .background).async {
let addressBook = ABAddressBook.shared()
let people = addressBook?.people()
let stepPercent = 100 / (people?.count)!
for person in people! as! [ABPerson] {
print(person)
DispatchQueue.main.async {
self.ProgressIndicator.increment(by: Double(stepPercent))
}
}
我的解决方案:
DispatchQueue.global(qos: .background).async {
let addressBook = ABAddressBook.shared()
let people = addressBook?.people()
print(Double((people?.count)!))
let stepPercent = 100.00 / (Double((people?.count)!))
print(stepPercent)
for person in people! as! [ABPerson] {
print(person)
DispatchQueue.main.async {
self.ProgressIndicator.increment(by: Double(stepPercent))
}
}
感谢支持