Does anyone use this? I can't get it working. I'm talking about code in normal swift files, not playgrounds.Example:/// 
/// 
///Neither one displays anything in the documentation popover or the Quick Help Inspector.The docs act like it works: https://developer.apple.com/library/archive/documentation/Xcode/Reference/xcode_markup_formatting_ref/Images.html#//apple_ref/doc/uid/TP40016497-CH17-SW1A lot of my code would really benefit from diagrams in documentation. I'd love to be able to use this.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I have a UI where you can navigate/push views like this: Root view > List of things > View thing > Edit thingThe "Edit thing" view can also delete it. After a delete, I want it to pop back to the "List of things". Best I've got now is to call `presentationMode.wrappedValue.dismiss()` on the "Edit thing" view, and then again in the "View thing" view, but that time inside DispatchQueue.main.async { }. It works but the double animation is kind of clunky.Is there a better way?
I'm working on a macOS SwiftUI app. I notice that Button text does not change color properly when the app changes between Dark and Light mode. Shouldn't the builtin Button be handling this automatically? The Text views seem to handle it fine and switch their text from white to black.
The Button text can become completely invisible when I go from Dark to Light mode. Restarting the app fixes it.
I can change the Dark/Light mode manually in System preferences, or it changes at certain times of day because I have it set, usually, to "Auto".
I have a View with a DragGesture to resize something, so I tried using onHover to set the macOS cursor to the right resize icon. It doesn't work 100%, because the drag will reset the cursor. Then I have to move the pointer out of the view and back in, to re-trigger the onHover and get the resize cursor again.
swift
private struct HeaderEdgeDragArea: View {
var drag: some Gesture {
DragGesture(minimumDistance: 0, coordinateSpace: .global)
.onChanged { value in
...
}
.onEnded { _ in
...
}
}
var body: some View {
Color.gray.zIndex(2.0).frame(width: 1.0)
.overlay(
Rectangle().frame(width: 8)
.foregroundColor(.clear)
.contentShape(Rectangle())
.border(Color.red, width: 0.5)
.onHover { hovering in
print("hovering: \(hovering)")
if hovering {
NSCursor.resizeLeftRight.push()
} else {
NSCursor.pop()
}
}
.gesture(drag)
)
}
}
Is there a way to quickly confirm a "fix-it" popup using only the keyobard?
The "Fix Next Issue" and "Fix Previous Issue" commands just show the popup. I still have to manually press the "Fix" button. Return key simply dismisses the popup. Clicking that tiny button 1000's of times is annoying.
Xcode 12.4.
In IntelliJ I can fly through these with a nice keyboard shortcut. I'm looking for a similar thing in Xcode.
These are properties of Product. Both are type VerificationResult<Transaction>? and they seem very similar. What are some example situations where they would be different?
It would be nice if the documentation discussed this.
This minimal code demonstrates a problem I'm having. As you adjust the Slider (high precision numbers), the TextField sets the model, changing the number's precision to its format.
But I only want it to use the 3-digit fraction for display, or if the user edits in the field. It shouldn't be mutating the model just because it's displaying the value, no?
Is it a bug? It doesn't seem right to me.
struct ContentView: View {
@State var number: Double = 0
// wrap binding to log the `set` calls
var textFieldBinding: Binding<Double> {
Binding { number } set: {
print("Setting from TextField: \($0)")
number = $0
}
}
var sliderBinding: Binding<Double> {
Binding { number } set: {
print("Setting from Slider: \($0)")
number = $0
}
}
var body: some View {
VStack {
TextField("Number", value: textFieldBinding, format: .number.precision(.fractionLength(3)))
Slider(value: sliderBinding, in: 0...5.0)
}.frame(maxWidth: 300)
}
}
When you drag the slider, you see stuff like:
Setting from Slider: 1.0073260217905045
Setting from TextField: 1.007
...
Why the does this display "Hello1" and not "HelloWorld"? Then if I put a space between them it works as expected.
(macOS 12.0.1)
struct ContentView: View {
var body: some View {
let t1 = Text("Hello").foregroundColor(.red)
let t2 = Text("World").foregroundColor(.blue)
Text("\(t1)\(t2)")
.padding()
.frame(width: 200)
}
}
Is this a bug? Is the < character supposed to change something in markdown? I didn't think so.
(Xcode 13.1)
I'm using the Connect app on my iPad. I'm looking at an app that is barely used, and I see two written reviews. But in the App Store there is only one. Any ideas what could cause this?
The review in question is reporting a possible bug, so I do wonder if this means the user retracted/deleted it.
I can't debug my metal shaders anymore. The GPU button just says this:
I have a lot of metal code so I'm not sure what triggered it. The "?" button does nothing.
Any pointers on where to look? Are there certain APIs that do this?
I have developer documentation that contains links that are now dead. How can I find the post that this link used to refer to?
https://forums.developer.apple.com/message/281700
I tried simply using the ID in the new URL format, but that didn't work. Eg:
https://developer.apple.com/forums/thread/281700
My project builds after a clean, but then fails to build. I can't understand these error messages. I have a macOS app target ("MyArchives") and a library target ("HelpPG") in the project. The app uses the library. Logically, there is no cycle.
The library is an attempt to wrap PostgreSQL's libpq with some Swift stuff. It works when it runs after the clean build.
I don't know what it's talking about with "headers before sources". That is already the case for the library target. There are no headers in the app target (which is all Swift).
For readability, strings were substituted:
[DEBUG] = /Users/me/Library/Developer/Xcode/DerivedData/MyArchives-flyvnqgqeolefjeztyopfnoaqmaj/Build/Products/Debug
[UUID1] = bb030422ec80ba11076c24bcbd7fcd674d61e6313e2915ec58f3544977cb99a4
[UUID2] = bb030422ec80ba11076c24bcbd7fcd67db6f662ae7c65be0e231d735b4905dc3
Showing All Messages
Cycle in dependencies between targets 'MyArchives' and 'HelpPG'; building could produce unreliable results. This usually can be resolved by moving the target's Headers build phase before Compile Sources.
Cycle path: MyArchives → HelpPG → MyArchives
Cycle details:
→ Target 'MyArchives' has copy command from '[DEBUG]/libHelpPG.dylib' to '[DEBUG]/MyArchives.app/Contents/Frameworks/libHelpPG.dylib'
→ Target 'HelpPG' has link command with output '[DEBUG]/libHelpPG.dylib'
○ Target 'HelpPG' has copy command from '/usr/local/pgsql/lib/libpq.5.13.dylib' to '[DEBUG]/libpq.5.13.dylib'
○ Target 'HelpPG' has link command with output '[DEBUG]/libHelpPG.dylib'
Raw dependency cycle trace:
target: ->
node: <all> ->
command: <all> ->
node: [DEBUG]/MyArchives.app/Contents/Frameworks/libHelpPG.dylib ->
command: target-MyArchives-[UUID1]-:Debug:PBXCp [DEBUG]/libHelpPG.dylib [DEBUG]/MyArchives.app/Contents/Frameworks/libHelpPG.dylib ->
node: [DEBUG]/libHelpPG.dylib/ ->
directoryTreeSignature: ~ ->
directoryContents: [DEBUG]/libHelpPG.dylib ->
node: [DEBUG]/libHelpPG.dylib ->
CYCLE POINT ->
command: target-HelpPG-[UUID2]-:Debug:Ld [DEBUG]/libHelpPG.dylib normal ->
node: [DEBUG]/libpq.5.13.dylib ->
command: target-HelpPG-[UUID2]-:Debug:PBXCp /usr/local/pgsql/lib/libpq.5.13.dylib [DEBUG]/libpq.5.13.dylib ->
node: <target-HelpPG-[UUID2]--phase1-compile-sources> ->
command: Gate target-HelpPG-[UUID2]--phase1-compile-sources ->
node: <Linked Binary [DEBUG]/libHelpPG.dylib> ->
command: target-HelpPG-[UUID2]-:Debug:Ld [DEBUG]/libHelpPG.dylib normal
Hard to believe something this old doesn't work, but it appears so. I set the top to 10 and the bottom to 0, but it uses 10 for both.
Am I doing something wrong, or is it a bug?
sv.edgeInsets = .init(top: 10, left: 10, bottom: 0, right: 0)
Screenshot:
Full code example below.
(This is the ViewController.swift file after creating a new Xcode project with "Interface" of "Storyboard". No other changes to the project template.)
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
let sv = NSStackView()
sv.translatesAutoresizingMaskIntoConstraints = false
let v1 = ColoredBlock(.red, width: 20)
let v2 = ColoredBlock(.green, width: 20)
let v3 = ColoredBlock(.blue)
sv.addArrangedSubview(v1)
sv.addArrangedSubview(v2)
sv.addArrangedSubview(v3)
sv.spacing = 0
sv.edgeInsets = .init(top: 10, left: 10, bottom: 0, right: 0)
// sv.setContentHuggingPriority(.required, for: .vertical)
view.addSubview(sv)
pinToFourEdges(view, sv)
}
}
class ColoredBlock: NSView {
let intrinsicHeight: CGFloat
let intrinsicWidth: CGFloat
init(_ color: NSColor, width: CGFloat = NSView.noIntrinsicMetric, height: CGFloat = NSView.noIntrinsicMetric) {
intrinsicWidth = width
intrinsicHeight = height
super.init(frame: .zero)
self.wantsLayer = true
if let layer = self.layer {
layer.backgroundColor = color.cgColor
}
}
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
override var intrinsicContentSize: NSSize {
return NSSize(width: intrinsicWidth, height: intrinsicHeight)
}
}
public func pinToFourEdges(_ view1: NSView, _ view2: NSView) {
view1.topAnchor.constraint(equalTo: view2.topAnchor).isActive = true
view1.bottomAnchor.constraint(equalTo: view2.bottomAnchor).isActive = true
view1.leftAnchor.constraint(equalTo: view2.leftAnchor).isActive = true
view1.rightAnchor.constraint(equalTo: view2.rightAnchor).isActive = true
}
In SwiftUI on macOS, you can add items to the main menu by using things like CommandGroup, CommandMenu.
But the default menus already have items. For example, the Edit menu has Undo, Redo, Cut, Copy, Paste, Delete, Select All. Those menu items are grayed out and don't do anything. Is there a way to hook some Swift code to these? Or do you just use CommandGroup(replacing: ...) to replace them? That doesn't seem right; why put them there if you just have to replace them?
Besides hooking up a function to run when they get clicked, I'd like to know how to enable and disable them depending on app state.
WindowGroup {
MyContentView()
}.commands {
SidebarCommands()
CommandGroup(after: .newItem) {
Button { newFolder() } label: { Text("New Folder") }
.keyboardShortcut("n", modifiers: [.command, .option])
}
}