You used to be able to put two wheel Pickers side-by-side in an HStack, if you used .frame(...) to set the width, along with .clipped().
Example code from previous question here: https://developer.apple.com/forums/thread/127028
HStack(spacing: 0) {
Picker(selection: $choice1, label: Text("C1")) {
ForEach(0..<10) { n in
Text("\(n) a").tag(n)
}
}
.pickerStyle(.wheel)
.frame(minWidth: 0)
.clipped()
// repeat with second Picker
}
This is not working for me now in iOS 15. The views still appear side by side, but the touch area seems to overlap. When you try to adjust the first wheel, it spins the second one. I can move the first wheel, if I touch way over to the leading side of the screen.
(I had to add the explicit Picker style. It seems like defaulting to .menu also started in iOS 15. ?)
Post
Replies
Boosts
Views
Activity
Simple code like this gives an error.
struct MyView: View {
@State private var test: Bool = false
var body: some View {
Text("Hello. \(test)")
The error:
Instance method 'appendInterpolation(_:formatter:)' requires that 'Bool' inherit from 'NSObject'
What is going on?
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.
After updating to 12.5, I now get an error trying to run my unit tests. This is for a macOS app.
dyld: warning: could not load inserted library '/[...]/DerivedData/[...]/Contents/Frameworks/libXCTestBundleInject.dylib' into hardened process because no suitable image found. Did find:
/[...]/libXCTestBundleInject.dylib: code signature in (/[...]/libXCTestBundleInject.dylib) not valid for use in process using Library Validation: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?)
Anyone else face and fix this, or understand what it is?
I changed the "Signing Certificate" in my test target to "Sign to Run Locally" (from "Development") to see if that would help. It didn't fix it.
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.
I've been using the os.Logger API, but it looks like I need to create an OSLog as well if I want to use the signpost API for tracking performance.
Is that true, or is there some way get an underlying OSLog from a Logger? Then I could write something like:
swift
extension os.Logger {
func signpost(...) {
os_signpost(.begin, ... self.osLog, ...)
}
}
I know how to add items to the main menu. But what if I want to connect a handler to one that is already there by default? (For example "Select All").
WindowGroup {
ContentView()
}.commands {
CommandGroup(after: CommandGroupPlacement.pasteboard) {
Button("Select All") { selectAll() }
}
That adds a second "Select All" menu item.
If I use CommandGroup(replacing: ...) then it replaces others, not just the "Select All"
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)
)
}
}
I'm running this on macOS. I looks like a bug to me. If I activate the menu item and confirm the alert, the alert pops up again. It only double-shows once; then it behaves correctly. In my real app, it double-shows every time.
If I uncomment that DispatchQueue.main.async, it "fixes" it.
macOS 11.2.3, Xcode 12.4.
swift
@main
struct DoubleAlertApp: App {
@State var showAlert: Bool = false
@StateObject var model: Model = .init()
var body: some Scene {
WindowGroup {
ContentView().environmentObject(model)
.background(EmptyView()
.alert(isPresented: $showAlert) {
Alert(title: Text("Test"),
message: Text("This will do something"),
primaryButton: .cancel(),
secondaryButton: .destructive(Text("Do it"), action: confirmedAction))
})
}.commands {
CommandGroup(replacing: CommandGroupPlacement.newItem) {
Button(action: testAlert) {
Text("Test Alert")
}.keyboardShortcut("t")
}
}
}
private func testAlert() {
showAlert = true
}
private func confirmedAction() {
print("confirmedAction")
// DispatchQueue.main.async {
self.model.change()
//}
}
}
class Model: ObservableObject {
init() {}
@Published var foo: Int = 0
func change() {
objectWillChange.send()
foo += 1
}
}
struct ContentView: View {
@EnvironmentObject var model: Model
var body: some View {
Text("Hello. \(model.foo)").padding()
}
}
I have a TextField in my toolbar that I use for a search function. I want to trigger the search by hitting the "return" key in this field. But if I do it in onCommit, the search also gets triggered when the user un-focuses the field.
Is there a way to respond to just the "return" key?
TextField("Search", text: $searchQuery) { editing in
print("onEditingChanged \(editing)")
} onCommit: {
// Problem: this is triggered by both
// 1. Return key
// 2. Losing focus
searchModel.startSearch(query: searchQuery)
}
Hi,
If I change the AppIcon in Xcode's Assets.xcassets, and rerun my app, the image used in the dock and app switcher does not update. If I "Clean Build Folder", and re-run, then it updates.
This is annoying when I keep tweaking the colors in the icon and want to see how they look. A full rebuild takes a while, because I have a few Swift Package dependencies.
Anyone know a trick to get the AppIcon to stop caching (or whatever it's doing)?
I tried killall Dock and killall Finder, but that didn't help.
(macOS 11.2.3)
Rob
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".
My app crashes and Xcode shows no stack trace. It just pops up some line of assembly language in __pthread_kill, and shows this in the console:
[error] precondition failure: invalid value type for attribute: 230424 (saw PreferenceKeys, expected ViewList) AttributeGraph precondition failure: invalid value type for attribute: 230424 (saw PreferenceKeys, expected ViewList).
Seems like a bug in SwiftUI. Any ideas? This is on macOS 11.
If I purchase a product with a test session in my unit test, everything works as expected. I see a purchased transaction on my payment queue.
But if I set the property to make it fail, nothing happens. Shouldn't I observe a transactions with transactionState == .failed?let session = try! SKTestSession(configurationFileNamed: "Configuration")
session.disableDialogs = true
session.clearTransactions()
session.failTransactionsEnabled = true
session.failureError = .unknown
session.buyProduct(productIdentifier: productID)
Has anyone used this?
This observer normally gets called. But not when I set failTransactionsEnabled. public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
There are some useful things that I could do with Autolayout that still seem near impossible with SwiftUI.
For some of these trickier situations, I've seen example code (not from Apple) that uses SwiftUI's "preferences" plus GeometryReader to achieve something like a constraint. But the code is very ugly (in my opinion), and it sometimes logs runtime warning messages about changing state during layout. And I've never seen anyone from Apple say "yes, that's how we imagined you using that preferences API". So it seems like a hack.
Examples of things that are easy in Autolayout but have no obvious equivalent in SwiftUI, that I know of:
Aligning elements in different branches of view tree
For example, a form-like layout with labels and editable fields. You want to say "make the labels equal width, or trailing-aligned". Each row might be in a HStack. If you make each column a VStack, you have the same problem in the vertical direction, if some of your right-side fields are different heights.					 Name: [ text field ]
Favorite color: [ text field ]
		Description: [ text area ]
								 [					 ]
				Enabled: [checkbox]
This is the kind of thing I've seen hacked with "preferences".
2. Center a label but slide it if needed | Left text			 Center text							 |
Maybe that's a header at the top of the screen. Imagine for some some languages or font preference, the left side text grows. You'd want to slide the center text over. That's easy with autolayout and constraint priorities. I have no clue how to do it with SwiftUI.| Long Russian left text		Center text			 |
Those are two examples I can remember. Maybe people can post more.
I'd love to know what Apple's SwiftUI devs think of that Preferences quasi-constraint hack, or if people have nice solutions to the examples above.