How to implement guide with appkit nsview layer backing causing unexpected flickering on macos 13.3
I'm trying to debug I'm experiencing a frustrating flickering scenario with a custom `NSView` that uses layer-backed views on macOS 13.3. The view is supposed to render some graphics using Core Graphics, and I have enabled layer backing by setting `wantsLayer` to `true`. However, during some animations, especially when resizing the window, the view flickers noticeably, which affects the user experience. Hereβs a simplified version of my `NSView` subclass: ```swift class CustomView: NSView { override func awakeFromNib() { super.awakeFromNib() wantsLayer = true layer?.backgroundColor = NSColor.white.cgColor } override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) guard let context = NSGraphicsContext.current?.cgContext else { return } context.setFillColor(NSColor.blue.cgColor) context.fill(dirtyRect) } } ``` I've tried setting the `isOpaque` property to `true` and adjusting the `wantsLayer` flag, but nothing seems to eliminate the flickering. Additionally, I have disabled the default animations using `NSAnimationContext.runAnimationGroup`, but the scenario continues. Changing the layer's contents directly, like using `layer?.contents`, introduces a further delay in rendering. I also noticed that this question doesn't occur when I use a non-layer-backed view. Is there a best practice to optimize layer-backed views in macOS 13.3 to avoid this flickering? Any insights would be greatly appreciated! For context: I'm using Swift on Linux. I'm on Windows 10 using the latest version of Swift. Thanks, I really appreciate it!