Проверка шаблона шины для iOS

128 行
3.0KB

  1. import BusX
  2. import Combine
  3. import MeetupIdX
  4. import MicX
  5. import SwiftUI
  6. import UIKit
  7. struct Content: View {
  8. @State private var selectedId = "1"
  9. var ids = ["1", "2", "3", "4"]
  10. @StateObject var adates = BusUI.Value(Mic.K.activityDates, [String: Date]())
  11. func val(_ k: String) -> String {
  12. let dt = adates.v[k] ?? .distantPast
  13. return String(describing: Int(dt.timeIntervalSince1970))
  14. }
  15. var body: some View {
  16. VStack {
  17. HStack {
  18. Text("MicItem id:")
  19. Picker("", selection: $selectedId) {
  20. ForEach(ids, id: \.self) {
  21. Text($0)
  22. }
  23. }
  24. }
  25. .pickerStyle(.segmented)
  26. Divider()
  27. .padding()
  28. MicItem.V(selectedId)
  29. Divider()
  30. .padding()
  31. List {
  32. ForEach(ids, id: \.self) {
  33. Text("\($0): \(val($0))")
  34. }
  35. }
  36. }
  37. .padding()
  38. }
  39. }
  40. @UIApplicationMain
  41. class AppDelegate: UIResponder, UIApplicationDelegate
  42. {
  43. let meetupIS = MeetupId.Service(.init())
  44. let micS = Mic.Service(.init())
  45. var window: UIWindow?
  46. func application(
  47. _ application: UIApplication,
  48. didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  49. ) -> Bool {
  50. window = UIWindow(frame: UIScreen.main.bounds)
  51. let vc = UIViewController()
  52. addSwiftUIViewAsChild(swiftUIView: Content(), parent: vc.view)
  53. vc.view.backgroundColor = .white
  54. window?.rootViewController = vc
  55. window?.backgroundColor = UIColor.white
  56. window?.makeKeyAndVisible()
  57. /**/print("ИГР App.didFLWO")
  58. //testMic1()
  59. //testMic2()
  60. //testMic2_id("1")
  61. /*
  62. DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
  63. self.testMic2_id("2")
  64. }
  65. */
  66. testMic4()
  67. return true
  68. }
  69. func testMic1() {
  70. DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
  71. Bus.send(Mic.K.isActive, true)
  72. }
  73. DispatchQueue.main.asyncAfter(deadline: .now() + 4) {
  74. Bus.send(Mic.K.isActive, false)
  75. }
  76. }
  77. func testMic2() {
  78. DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
  79. Bus.send(Mic.K.activityDate, Date() + 2)
  80. }
  81. DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
  82. Bus.send(Mic.K.activityDate, Date() + 2)
  83. }
  84. DispatchQueue.main.asyncAfter(deadline: .now() + 6) {
  85. Bus.send(Mic.K.activityDate, Date() + 7)
  86. }
  87. }
  88. var subscriptions = [AnyCancellable]()
  89. func testMic2_id(_ id: String) {
  90. DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
  91. Bus.send(Bus.keyId(Mic.K.activityDate, id), Date() + 2)
  92. }
  93. DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
  94. Bus.send(Bus.keyId(Mic.K.activityDate, id), Date() + 2)
  95. }
  96. DispatchQueue.main.asyncAfter(deadline: .now() + 6) {
  97. Bus.send(Bus.keyId(Mic.K.activityDate, id), Date() + 3)
  98. }
  99. }
  100. func testMic4() {
  101. delayedSend(2, Mic.K.activeIds, ["1"])
  102. delayedSend(4, Mic.K.activeIds, ["1", "4"])
  103. }
  104. func delayedSend(
  105. _ delay: TimeInterval,
  106. _ key: String,
  107. _ value: Any
  108. ) {
  109. DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
  110. Bus.send(key, value)
  111. }
  112. }
  113. }