SwiftUWhy
Welcome to my new series on things I don’t understand about Apple’s premier user interface framework.
[…]
To be clear, these are things I don’t understand, not necessarily things that are “wrong.” They sure look wrong (or at least “suboptimal”) to me! But maybe there are good reasons, and I just don’t know them yet. SwiftUI experts and historians, please tell me!
Previously:
Update (2025-01-10): John Siracusa (GitHub):
Why is there (apparently?) no
Picker
style on macOS that can be configured with a fixed width, likeNSPopUpButton
in AppKit?For example, consider a text field for numeric input followed by a picker for units, both aligned to the right side of a System Settings-style Form. Each time you pick a different unit, the
Picker
changes width and moves the text field.
Q: Why is Xcode no longer able to render a preview of my SwiftUI view?
A: Sometimes, the answer is that you’ve got a call to a log method on a
Logger
object in a code path that’s executed when rendering a preview but rarely or not at all otherwise, and this call passes a string without any values interpolated into it (e.g.,logger.log("Hello")
). This causes an error, and this error is only visible in the big spew of output available through the stethoscope icon in the preview pane.
ScrollView
on macOS includes default support for swipe gestures and mouse scroll wheels, but not page up/down, home/end, or arrow keys?
See also: the Mastodon tag.
Update (2025-01-17): John Siracusa:
Why can’t I find a simple way to do this?
.textSelection(allowSelection ? .enabled : .disabled)