我想获取当前计数以更新到我的 Firebase。
我正在制作一个基本的计数计数器,我希望能够跨设备实时更新(ish)。
Firebase 身份验证已配置并链接到应用程序。
class CurrentCount: ObservableObject {
@Published var count = 0 }
struct HomeScreen : View {
@ObservedObject var UserCount = CurrentCount()
var body: some View {
ZStack {
VStack {
Button(action: {
self.UserCount.count -= 1
}) {
Image(systemName: "minus")
.foregroundColor(Color("Color"))
.scaleEffect(2)
.padding()
.frame(minWidth:1000, maxWidth: 1000)
.frame(minHeight:450, maxHeight: 450)
}
Button(action: {
}) {
Text("\(UserCount.count)")
.foregroundColor(Color("Color"))
.font(.system(size: 100))
.padding()
.onLongPressGesture {
self.UserCount.count = 0
}
}
}
Button(action: {
self.UserCount.count += 1
}) {
Image(systemName: "plus")
.foregroundColor(Color("Color"))
.scaleEffect(2)
.padding()
.frame(minWidth:1000, maxWidth: 1000)
.frame(minHeight:450, maxHeight: 450)
}
}
}
}