Post

Replies

Boosts

Views

Activity

Reply to SwiftUI Timer not working inside Menu bar extra
Using a dedicated obervable object with a timer being initialized there will perfectly work while the open menu is blocking the runloop from SwiftUI. public final class MyObject: ObservableObject { @Published var showItem: Bool = false var cancellable = Set<AnyCancellable>() init() { Timer.publish(every: 5, on: .main, in: .common) .autoconnect() .sink(receiveValue: { [weak self] value in print(value) self?.showItem = true }) .store(in: &cancellable) } } And within the MenuBarExtra content closure, you can use something like: if myObject.showItem{ Button("Item 2") { } }
Oct ’23