更新 PromiseKit 后出错:无法将类型 'PMKFinalizer' 的值转换为预期的参数类型 'Promise<Void>'
Error after update PromiseKit: Cannot convert value of type 'PMKFinalizer' to expected argument type 'Promise<Void>'
此代码适用于 PromiseKit v.4.5.2。
func getReminderIds(idArray: [Int]) {
var reminderPromises: [Promise<Void>] = []
for id in idArray {
if let prom = self.delegate?.getReminders(id).then({ (reminderArray) -> Promise<Void> in
Utils.logMessage("Reminders for asset \(id): \(reminderArray)")
self.reminders[String(id)] = reminderArray
}).catch({ (err) in
self.reminders[String(id)] = nil
Utils.logMessage("Error getting reminders for asset \(id): \(err)")
}){
reminderPromises.append(prom)
}
}
_ = when(fulfilled: reminderPromises).done { results -> Void in
self.collectionView?.refreshCollection(collection: 0)
}
}
但是在更新到 PromiseKit v.6.8.4 之后我得到了错误
"Cannot convert value of type 'PMKFinalizer' to expected argument type 'Promise'"
在这一行中:
reminderPromises.append(prom)
struct Reminder {
let id: Int
let value: [String: Any]
}
func getReminderIds(idArray: [Int]) {
var reminderPromises: [Promise<Reminder>] = []
for id in idArray {
reminderPromises.append(getReminders(id))
}
_ = when(fulfilled: reminderPromises).done { results -> Void in
for item in results {
print(item.id)
print(item.value)
}
}
}
func getReminders(_ id: Int) -> Promise<Reminder> {
// TODO network request or database request
return Promise { [=10=].fulfill(Reminder(id: id, value: [:])) }
}
此代码适用于 PromiseKit v.4.5.2。
func getReminderIds(idArray: [Int]) {
var reminderPromises: [Promise<Void>] = []
for id in idArray {
if let prom = self.delegate?.getReminders(id).then({ (reminderArray) -> Promise<Void> in
Utils.logMessage("Reminders for asset \(id): \(reminderArray)")
self.reminders[String(id)] = reminderArray
}).catch({ (err) in
self.reminders[String(id)] = nil
Utils.logMessage("Error getting reminders for asset \(id): \(err)")
}){
reminderPromises.append(prom)
}
}
_ = when(fulfilled: reminderPromises).done { results -> Void in
self.collectionView?.refreshCollection(collection: 0)
}
}
但是在更新到 PromiseKit v.6.8.4 之后我得到了错误 "Cannot convert value of type 'PMKFinalizer' to expected argument type 'Promise'" 在这一行中:
reminderPromises.append(prom)
struct Reminder {
let id: Int
let value: [String: Any]
}
func getReminderIds(idArray: [Int]) {
var reminderPromises: [Promise<Reminder>] = []
for id in idArray {
reminderPromises.append(getReminders(id))
}
_ = when(fulfilled: reminderPromises).done { results -> Void in
for item in results {
print(item.id)
print(item.value)
}
}
}
func getReminders(_ id: Int) -> Promise<Reminder> {
// TODO network request or database request
return Promise { [=10=].fulfill(Reminder(id: id, value: [:])) }
}