Last active
August 30, 2020 00:35
-
-
Save laevandus/6e0ce97b57fbb18a5624ecc220010ea4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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