In a triple-column split view, it's common to hide the primary view when the user selects an item from a list.
In some cases, the supplemental view is also hidden when an item is selected from that list, thus leaving only the detail view visible.
What is the correct way to hide the primary view on selection and then to optionally hide the supplemental view on selection using the new NavigationStack?
(Notes is a good example of the sidebars hiding after the user selects a folder in the sidebar.)
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I'm trying to use an NSImage that represents an SF Symbol as the contents of a CALayer. NSImage has an API for this in the form of [NSImage layerContentsForContentsScale:]. On the NSImage documentation page, there's even a few paragraph at the top dedicated to using this very method.
But how do you set the color you want the image to render as if the image is an SF Symbol? NSImageView has .contentTintColor which works great, but CALayer has no such property.
final class SymbolLayer: CALayer {
func display() {
// Just an example...
let image = NSImage(systemSymbolName: "paperclip", accessibilityDescription: nil)!
let actualScaleFactor = image.recommendedLayerContentsScale(contentsScale)
// This obviously produces a black image because there's no color or tint information anywhere.
contents = image.layerContents(forContentsScale: actualScaleFactor)
}
}
Is there a way you can configure the CALayer or the NSImage itself to have some sort of color information when it generates the layer contents? I've attempted to play around with the SymbolConfiguration coolers but without any success. (Even when wrapped inside NSAppearance.performAsCurrentDrawingAppearance.)
The best I can come up with is to use CALayer.draw(in:) and then use the old NSImage.cgImage(forProposedRect:...) API. I can then set the fill color on the CGContext and go from there. Is there a more efficient way?
override func draw(in context: CGContext) {
let image = NSImage(systemSymbolName: "paperclip", accessibilityDescription: nil)!
var rect = bounds
image.size = bounds.size
let cgImage = image.cgImage(
forProposedRect: &rect,
context: nil,
hints: [.ctm: AffineTransform(scale: contentsScale)]
)!
NSApp.effectiveAppearance.performAsCurrentDrawingAppearance {
// Draw using an Appearance-sensitive color.
context.clip(to: bounds, mask: cgImage)
context.setFillColor(NSColor.labelColor.cgColor)
context.fill(bounds)
}
}
This is for macOS 12+.
Given an XPC process, what is the most efficient way to get data back to the host application? I have an XPC process, primarily written in C++ and a host application written in Swift. It generates a bunch of data that it serializes into an std::vector<std::byte>. When the process is finished, I want to efficiently transfer that buffer of bytes back to the host application. At the moment, I copy the std::vector data() into an NSData, then encode that NSData into an object conforming to NSSecureCoding that is then sent back to the app. At a minimum this is creating two copies of the data (one in the vector and the other in the NSData) but then I suspect that the XPC transporter might be creating another? * When using NSData, can I use the bytesNoCopy version if I guarantee that the underlying vector is still alive when I initiate the XPC connection response? When that call returns, am I then free to deallocate the vector even if the NSData is still in-flight back to the main app? * In one of the WWDC videos, it is recommended to use DispatchData as DispatchData might avoid making a copy when being transported across XPC. Does this apply when using NSXPCConnection or only when using the lower-level C APIs? * Is there a downside to using DispatchData that might increase the overhead? * Finally, where does Swift's Data type fit into this? On the application side, I have Swift code that is reading the buffer as a stream of bytes, so I ideally want the buffer to be contiguous and in a format that doesn't require another copy in order for Swift to be able to read it. (On average, the buffers tend to be small. Maybe only 1-2 megabytes, if that. But occasionally a buffer might ballon to 100-200 megabytes.)