Post

Replies

Boosts

Views

Activity

Best practices to use low-latency feature in UIUpdateLink?
Hi everyone, I'm not an experienced developer. I'm interested in the low-latency related APIs in UIUpdateLink, but I failed to write even a minimal demo that works. UIUpdateInfo.isImmediatePresentationExpected is always false here. My understanding must be wrong. I've totally no idea so I'm asking for help here. I appreciate anyone who gives suggestions of any kind. Here's my (failed) demo about tracking touch inputs (of the 1st finger) and draw some shape at that place: import UIKit class ContentUIView: UIView { // MARK: - About UIUpdateLink and drawing required init?(coder: NSCoder) { super.init(coder: coder) initializeUpdateLink() } override init(frame: CGRect) { super.init(frame: frame) initializeUpdateLink() } private func initializeUpdateLink() { self.updateLink = UIUpdateLink(view: self) self.updateLink.addAction(to: .beforeCADisplayLinkDispatch, target: self, selector: #selector(update)) self.updateLink.wantsImmediatePresentation = true self.updateLink.isEnabled = true } @objc func update(updateLink: UIUpdateLink, updateInfo: UIUpdateInfo) { print(updateInfo.isImmediatePresentationExpected) // FIXME: Why always false? CATransaction.begin() defer { CATransaction.commit() } layer.setNeedsDisplay() layer.displayIfNeeded() } override func draw(_ rect: CGRect) { // FIXME: Any way to support opacity? guard let context = UIGraphicsGetCurrentContext() else { return } context.clear(rect) guard let lastTouch = self.lastTouch else { return } let location = lastTouch.location(in: self) let circleBounds = CGRect(x: location.x - 16, y: location.y - 16, width: 32, height: 32) context.setFillColor(.init(red: 1/2, green: 1/2, blue: 1/2, alpha: 1)) context.addLines(between: []) context.fillEllipse(in: circleBounds) } // MARK: - Touch input override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { super.touchesBegan(touches, with: event) guard lastTouch == nil else { return } lastTouch = touches.first } override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { super.touchesEnded(touches, with: event) guard let lastTouch, touches.contains(lastTouch) else { return } self.lastTouch = nil } override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) { self.touchesEnded(touches, with: event) } private var lastTouch: UITouch? private var updateLink: UIUpdateLink! } #Preview { ContentUIView() } Anyway, I'm not meant to find alternative APIs and I'd be willing to know what it can't do.
0
0
51
3d
Scene.windowIdealSize(.fitToContent) seems not working
Hi everyone, Something didn't work in my environment so I wrote some demo code: import SwiftUI @main struct DemoApp: App { var body: some Scene { WindowGroup { Color.accentColor.opacity(1/4) .frame(idealWidth: 800, idealHeight: 800) } .windowIdealSize(.fitToContent) } } I expected a 800*800 window (then +28pt top) using .windowIdealSize(.fitToContent). Otherwise I can't control these views that use up available space such as Color, Spacer, GeometryReader, etc. Was I missing something? Or this is a problem or intended framework design? Environments: macOS 15.4.1 (24E263) and 15.5 beta 4 (24F5068b) Xcode 16.3 (16E140)
2
0
58
May ’25
Xcode 16.3 repeatedly log causing CPU leak
Xcode 16.3 repeatedly logs a same message very frequently, as fast as a single thread can. I use Instruments and Console and find out the log is: Needs flush! by -[DNTBrotliDecoder decodeBytes:length:] in DNTDocumentationSupport. The call is on a single non-main thread. I've tried to clear caches and it seems doesn't change. Yet I don't know exact point when the logging starts since launch. Fortunately, this thread is dispatched at E cores, bringing approximately 2 watts of power load to my Mac. Environments: macOS 15.4 (24E248) Xcode 16.3 (16E140) M4 chip
7
3
219
Apr ’25