gpt4 book ai didi

swift - RxSwift BehaviourRelay 自动 isDispose

转载 作者:行者123 更新时间:2023-11-30 10:31:43 25 4
gpt4 key购买 nike

这是我的代码:

class MapManager: NSObject {

let removeFenceTask = BehaviorRelay<String?>(value: nil)

override init() {
super.init()

removeFenceTask
.filter({ $0 != nil })
.debug("removeFenceTask", trimOutput: true)
.flatMap { (taskId: String?) -> Observable<TaskModel> in
guard let `taskId` = taskId, let provider = Application.shared.provider else { return Observable.just(TaskModel()) }
return provider.queryTaskDetail(taskId: taskId).asObservable()
}
.asObservable()
.subscribe(onNext: { [weak self] (taskModel) in
self?.removeFence(taskModel: taskModel)
}).disposed(by: rx.disposeBag)

}
}
    func queryTasks(_ currentPage: Int, status: TaskStatus) -> Single<([TaskModel], Bool)> {
return requestObject(
.queryTasks(currentPage: currentPage, pageSize: 10, status: status), type: TaskModelWrapper.self)
.map({ (taskModelWrapper) -> ([TaskModel], Bool) in
let tasks = taskModelWrapper.data?.data ?? []
tasks.filter({ $0.taskStatus == .canceled || $0.taskStatus == .deliveryCompleted || $0.taskStatus == .taskCompleted || $0.taskStatus == .terminated })
.forEach { (taskModel) in
MapManager.shared.removeFenceTask.accept(taskModel.taskId)
}
return (tasks, taskModelWrapper.data?.isNoMoreDataShow ?? false)
})
}

在成功完成 2 个事件后,我终于得到了 isDispose

控制台:

2019-11-27 10:46:27.203:newFenceTask -> 已订阅

2019-11-27 10:46:27.203:removeFenceTask -> 已订阅

2019-11-27 10:46:27.204:removeFenceTask -> 事件下一个(可选(“123”))

2019-11-27 10:46:27.207:removeFenceTask -> 事件下一个(可选(“1908157SRZTT2DGF”))

2019-11-27 10:46:27.295:removeFenceTask -> isDispose

问题:为什么会发生此 isDispose 情况?

最佳答案

你的rx.disposeBag没有被丢弃吗?

关于swift - RxSwift BehaviourRelay 自动 isDispose,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59062353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com