Search code examples
iosswiftxcodeuiviewcontrollerpromisekit

PromiseKit 6 Reference to member 'value' cannot be resolved without a contextual type


An update from PromiseKit 4 to 6 was that this...

Promise(foo)

Has become...

.value(foo)

And this has worked for me throughout the entirety of updating my project except for one instance in my ContestListViewController.swift..

func confirmEntry(to contest: Contest, with lineup: Lineup) -> Promise<Lineup> {
    let entryConfirmationVC = EntryConfirmationViewController()
    entryConfirmationVC.configure(for: contest, lineup: lineup)
    return entryConfirmationVC.promise().then { seal in return .value(lineup) }
}

Which is giving me an error that reads...

Reference to member 'value' cannot be resolved without a contextual type

Here's the relevant information on EntryConfirmationViewController.swift

class EntryConfirmationViewController: DraftboardModalViewController {

    // 9 variable declarations
    // Removed code for readability

    let (pendingPromise, seal) = Promise<Void>.pending()

    // override func loadView()
    // Removed code for readability

    func promise() -> Promise<Void> {
        let defaults = UserDefaults.standard
        if defaults.bool(forKey: App.DefaultsDontAskToConfirmEntry) {
            seal.fulfill(())
            return pendingPromise
        }

        RootViewController.sharedInstance.pushModalViewController(nvc: self)
        return pendingPromise
    }

    func configure(for contest: Contest, lineup: Lineup) {
        confirmationLabel.text = contest.name.uppercased()
        prizeStatView.valueLabel.text = Format.currency.string(from: NSNumber(value: contest.prizePool))
        entrantsStatView.valueLabel.text = "\(contest.currentEntries)"
        feeStatView.valueLabel.text = Format.currency.string(from: NSNumber(value: contest.buyin))
        enterButton.setTitle("Enter “\(lineup.name)”".uppercased(), for: .normal)
    }

    // @objc func tappedEnterButton()
    // Removed code for readability

    // @objc func tappedCancelButton() 
    // Removed code for readability
}

How can I get confirmEntry in my ContestListViewContoller.swift to work like the rest of the .value(foo) calls?


Solution

  • You need to tell the compiler what you are returning from the then block,

    .then { seal-> Promise<Lineup> in return .value(lineup) }