gpt4 book ai didi

ios - 现在初始触发的计时器发布者

转载 作者:行者123 更新时间:2023-12-04 14:05:07 26 4
gpt4 key购买 nike

我有一个简单的计时器发布器,每 10 秒触发一次。

Timer
.publish(every: 10, on: .main, in: .common)
.autoconnect()
.map { _ in ... }
.sink(receiveValue: { [weak self] in
...
})
.store(in: &subscriptions)
但是,它第一次触发是在 10 秒后。我现在可以将它设置为触发它的第一个值吗?

最佳答案

我能够实现我想要的,但我不得不添加另一个发布者:

let timer = Timer
.publish(every: 10, on: .main, in: .common)
.autoconnect()
let initial = Just(Date.init())

timer.merge(with: initial)
.map { _ in ... }
.sink(receiveValue: { [weak self] in
...
})
.store(in: &subscriptions)

关于ios - 现在初始触发的计时器发布者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68808409/

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