ReactiveCocoa swift3迁移

时间:2016-11-25 14:07:53

标签: swift reactive-cocoa-3

我正在将一段代码从swift2翻译成swift 3。 我正在使用ReactiveCocoa,我的旧代码是这样的:

API.signin(withEmail: emailTextField.text!, password: passwordTextField.text!)
    .on(started: {
            SVProgressHUD.show()
        },
        failed: { [weak self] error in
            if error == .NotAuthorized {
                self?.view.window?.dodo.error("Not authorized")
            } else {
                self?.view.window?.dodo.error("An error occured !")
            }
        },
        terminated: {
            SVProgressHUD.dismiss()
        },
        next: { [weak self] user in
            print("user: \(user)")
            UserService.userId = user.identifier

            self?.emailTextField.text = nil
            self?.passwordTextField.text = nil
            self?.performSegueWithIdentifier(kRootSegueIdentifier, sender: self)
        })
    .start()

}

API.signin的类型为SignamProducer 看来"下一个:"已不再使用ReactiveCoca的新版本。我该怎么办?

1 个答案:

答案 0 :(得分:0)

现在变得有价值:如下所示

SignalProducer<Int, NoError>(value: 1)
        .on(value: {
            print("value = \($0)")
        })
        .start()