iosswiftpromisekit

Error after update PromiseKit: Cannot convert value of type 'PMKFinalizer' to expected argument type 'Promise<Void>'


This code worked with 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)
    }

}

But after updating to PromiseKit v.6.8.4 I get the error "Cannot convert value of type 'PMKFinalizer' to expected argument type 'Promise'" in this line:

reminderPromises.append(prom)

Solution

  • 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 { $0.fulfill(Reminder(id: id, value: [:])) }
        }