Post

Replies

Boosts

Views

Activity

How to force cancel a task that doesn't need cleanup and doesn't check for cancellation?
How can you force cancel a task that doesn't need cleanup and doesn't check for cancellation? If this cannot be done, would this be a useful addition to Swift? Here is the situation: The async method doesn't check for cancellation since it is not doing anything repetively (for example in a loop). For example, the method may be doing "try JSONDecoder().decode(Dictionary<String, ...>.self, from: data)" where data is a large amount. The method doesn't need cleanup. I would like the force cancellation to throw an error. I am already handling errors for the async method. My intended situation if that the user request the async method to get some JSON encoded data, but since it is taking longer that they are willing to wait, they would tap a cancellation button that the app provides.
1
0
70
May ’25
Observation on SwiftUI+DragGesture: GestureState is already reset when OnEnded starts
When I set up a dragGesture using a gestureState, the gestureState has the correct value during the onChange phase. But when the onEnded phase is entered, the gesturePhase is reset to its original default value. Is this the correct behavior? I would like the gestureState to retain its value since I want to make use of it in the onEnded phase. After the onEnded phase is completed, then the gestureState should be reset to its original value.
2
0
1.1k
Feb ’23
Problem: OSX + SwiftUI + SpriteKit + DragGesture
I am using Xcode 14.2 and running on Ventura 13.2. There is no problem working with iOS or the OSX playground. But there is a problem having it work with OSX. The first problem is that the DragGesture is not recognized on OSX: nothing happens on a drag of an SKNode. The second problem (using a kludge by putting a "glass pane" in front of the spriteView) is that the dragging now works, but the coordinate system is flipped. Here is the code: import SwiftUI import SpriteKit @main struct TestOnMacApp: App {     var body: some Scene {         WindowGroup {             ContentView()         }     } } struct ContentView: View {     @State private var gameScene = GameScene()     let glassPaneColor =         CGColor(red: 0, green: 0, blue: 0, alpha: 0.01)     var body: some View {         ZStack {             SpriteView(scene: gameScene) // Comment out the following line: drag won't work             Color(cgColor: glassPaneColor)         }         .gesture(DragGesture(minimumDistance: 0)             .onChanged { gesture in                 let location = gesture.location                 let sceneLocation =                     gameScene.convertPoint(fromView: location)                 gameScene.spriteNode.position = sceneLocation             })     } } class GameScene: SKScene {     let sceneSize = CGSize(width: 500, height: 500)     let nodeSize = CGSize(width: 50, height: 50)     let spriteNode: SKSpriteNode     required init?(coder aDecoder: NSCoder) {         fatalError("init(coder:) has not been implemented")     }     override init() {         spriteNode = SKSpriteNode(texture: nil, size: nodeSize)         super.init(size: sceneSize)         scaleMode = .resizeFill         backgroundColor = .white         spriteNode.name = "spriteNode"         spriteNode.color = .blue         spriteNode.position = CGPoint(x: 100, y: 100)         addChild(spriteNode)     } }
0
0
797
Jan ’23