gpt4 book ai didi

swift - RxSwift : Should groupBy send completed to each of its GroupedObservable's when the source is completed?

转载 作者:行者123 更新时间:2023-11-30 11:33:20 27 4
gpt4 key购买 nike

以下代码似乎永远不会工作,因为组似乎没有终止,并且 takeLast() 不知道最后是什么:

observableSequence
.groupBy { $0.key }
.map { groups in
groups
.takeLast(1)
.subscribe(onNext: { element in
print(element)
})
.disposed(by: self.disposeBag)
}
.subscribe()
.disposed(by: self.disposeBag)

最佳答案

答案是肯定的。

    Observable.from([1,2,3,4,5,6,7,8])
.groupBy { ($0 % 2) == 0 }
.subscribe(onNext: { group in
group
.takeLast(1)
.subscribe(onNext: { e in
print(e)
})
.disposed(by: self.disposeBag)
})
.disposed(by: self.disposeBag)

以上代码输出:

7

8

关于swift - RxSwift : Should groupBy send completed to each of its GroupedObservable's when the source is completed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50017112/

27 4 0