Post

Replies

Boosts

Views

Activity

Side by side Picker wheels failing in iOS 15
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. ?)
4
0
2.7k
Sep ’21
Can't run unit tests with Xcode 12.5. Code signing?
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.
3
0
4.4k
May ’21
Confirm Fix-it by keyboard shortcut? Return key doesn't do 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.
1
0
975
Apr ’21
Logger and signposts?
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, ...) } }
1
0
606
Apr ’21
How to respond to builtin main menu items like "Select All" in SwiftUI?
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"
0
1
457
Apr ’21
How to set cursor to show drag possibility - onHover fails
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)             )     } }
0
0
422
Apr ’21
SwiftUI bug: Alert shows twice?
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()     } }
2
0
2.0k
Mar ’21
Differentiating between "return" and focus loss in TextField onCommit
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) }
7
0
1.9k
Mar ’21
macOS app icon not updating. Cached?
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
5
0
3.7k
Mar ’21
Button text is invisible after dark/light mode change
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".
7
0
1.9k
Mar ’21
SwiftUI crash: AttributeGraph precondition failure
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.
7
1
8.4k
Mar ’21
SKTestSession failTransactionsEnabled not working
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]) {     
1
0
752
Dec ’20
SwiftUI vs. Autolayout - anyone else missing constraints?
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.&#9;&#9;&#9;&#9;&#9; Name: [ text field ] Favorite color: [ text field ] &#9;&#9;Description: [ text area ] &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; [&#9;&#9;&#9;&#9;&#9; ] &#9;&#9;&#9;&#9;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&#9;&#9;&#9; Center text&#9;&#9;&#9;&#9;&#9;&#9;&#9; | 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&#9;&#9;Center text&#9;&#9;&#9; | 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.
0
0
831
Oct ’20