尝试在我的项目中使用 ReativeSwift,但有些东西表现不佳,我检查了很多次,无法找出问题所在。一切都是正确的,只是没有调用。
class MSCreateScheduleViewModel: NSObject {
var scheduleModel = MSScheduleModel()
var validateAction: Action<(), Bool, NoError>!
override init() {
super.init()
validateAction = Action(execute: { (_) -> SignalProducer<Bool, NoError> in
return self.valiateScheduleModel()
})
validateAction.values.observeValues { (isok) in
print("isok??") //this line not called
}
validateAction.values.observeCompleted {
print("completed") //this line not called
}
}
func valiateScheduleModel() -> SignalProducer<Bool, NoError> {
let (signal, observer) = Signal<Bool, NoError>.pipe()
let signalProducer = SignalProducer<Bool, NoError>(_ :signal)
observer.send(value: true) //this line called
observer.sendCompleted() //this line called
return signalProducer
}
}