Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active August 30, 2020 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/6e0ce97b57fbb18a5624ecc220010ea4 to your computer and use it in GitHub Desktop.
Save laevandus/6e0ce97b57fbb18a5624ecc220010ea4 to your computer and use it in GitHub Desktop.
import Combine
import SwiftUI
struct BottomBarView: View {
@StateObject var viewModel: BottomBarViewModel
var body: some View {
Text(viewModel.text)
}
}
final class BottomBarViewModel: ObservableObject {
@Published var text: String = ""
private var cancellables = [AnyCancellable]()
private let entryStore: EntryStore
init(entryStore: EntryStore) {
self.entryStore = entryStore
print(self, #function)
cancellables.append(Timer.publish(every: 2, on: .main, in: .default).autoconnect().sink { [weak self] (_) in
self?.text = "Random number: \(Int.random(in: 0..<100))"
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment