From 53c95b4e3ad34f0a5ab1926b07a2fc82c955ad25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Sun, 28 Jan 2024 18:05:43 +0300 Subject: [PATCH] d --- src/App.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/App.swift b/src/App.swift index b3c4651..c35b3d9 100644 --- a/src/App.swift +++ b/src/App.swift @@ -5,6 +5,24 @@ import MicX import SwiftUI import UIKit +struct Now: View { + @State var refresh = false + let tm = Timer.publish(every: 0.5, on: .current, in: .common).autoconnect() + + var now: String { + "Now: " + String(describing: Int(Date().timeIntervalSince1970)) + } + + var body: some View { + Text(now) + .onReceive(tm) { _ in + self.refresh.toggle() + } + // Магия для обновления себя. + .background(Color.clear.disabled(refresh)) + } +} + struct Content: View { @State private var selectedId = "1" var ids = ["1", "2", "3", "4"] @@ -34,6 +52,7 @@ struct Content: View { MicItem.V(selectedId) Divider() .padding() + Now() List { ForEach(ids, id: \.self) { Text("\($0): \(val($0))")