Невозможно преобразовать значение типа '(Any) -> ()' в ожидаемый тип аргумента '(_) -> _' - PullRequest
0 голосов
/ 08 сентября 2018

Установка PromiseKit (6.2.1). Swift4.0.

import UIKit
import PromiseKit

class ViewController: UIViewController {
    func onFulfilled() -> (String) -> Promise<String> {
        return { result in
            return Promise<String> { seal in
                print(result)
                DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1), execute: {
                    seal.fulfill("Hello")
                })
            }
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        Promise.value("first")
            .then(onFulfilled())
            .then(onFulfilled())
            .then(onFulfilled())
            .then { result in print(result) } // Cannot convert value of type '(Any) -> ()' to expected argument type '(_) -> _'
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

Error

Невозможно преобразовать значение типа '(Any) -> ()' в ожидаемый тип аргумента '(_) -> _'

Как исправить

Как починить .then { result in print(result) }?

1 Ответ

0 голосов
/ 09 сентября 2018

заменить then на done.

_ = Promise.value("first")
            .then(onFulfilled())
            .then(onFulfilled())
            .then(onFulfilled())
            .done { result in print(result) }

см .: https://github.com/mxcl/PromiseKit/blob/master/Documentation/GettingStarted.md

сделано так же, как и тогда, но вы не можете вернуть обещание. Как правило, это конец «успеха» в цепочке.

...