Post

Replies

Boosts

Views

Activity

Why timer isn't working with button in SwiftUI
.onReceive construction isn't working with button long press gesture but tap is working, it increases count by 1. Construction should increase count every 0.5 seconds if button pressed struct Test: View { @State private var count = 0 @State private var isLongPressed = false var body: some View { VStack { Text("Count: \(count)") Button("Increase") { count += 1 print("Button tapped") } .onLongPressGesture { isLongPressed = true print("Long press started") } .onLongPressGesture(minimumDuration: 0) { isLongPressed = false print("Long press ended") } } .onReceive(Timer.publish(every: 0.5, on: .main, in: .common).autoconnect()) { _ in if isLongPressed { count += 1 print("Count increased: \(count)") } } } }
1
0
425
Jan ’25
Why timer isn't working with button in SwiftUI
.onReceive construction isn't working with button long press gesture but tap is working, it increases count by 1. Construction should increase count every 0.5 seconds if button pressed struct Test: View { @State private var count = 0 @State private var isLongPressed = false var body: some View { VStack { Text("Count: \(count)") Button("Increase") { count += 1 print("Button tapped") } .onLongPressGesture { isLongPressed = true print("Long press started") } .onLongPressGesture(minimumDuration: 0) { isLongPressed = false print("Long press ended") } } .onReceive(Timer.publish(every: 0.5, on: .main, in: .common).autoconnect()) { _ in if isLongPressed { count += 1 print("Count increased: \(count)") } } } }
Replies
1
Boosts
0
Views
425
Activity
Jan ’25
How to output CGFloat var in another SwiftUI View?
I have a wave and I can change height (progress var). How I can output it in Text on the screen in another view? Cup view When I doing wave higher or lower it printed in console I want to print on the screen I have no idea what write instead Binding (it's a suggestion by Xcode)
Replies
0
Boosts
0
Views
504
Activity
Apr ’23
Loading loop preview in Xcode
I tried clean project with Shift + Command + K, there is no errors but any file preview won't load in this project. App can be compiled and started on iPhone. How fix it? Xcode 13.2.1
Replies
2
Boosts
0
Views
4.3k
Activity
Apr ’22