Post

Replies

Boosts

Views

Activity

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
668
Apr ’21
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
3.0k
Dec ’21
SwiftUI sheet size control on iPad
I want to show a custom confirmation dialog on my iPad. It pops up looking utterly ridiculous because the size is way bigger than it needs - inches of padding on all sides. Is there still no way to control a sheet size on iPad? Example code: struct ContentView: View {     @State var showSheet = false     var body: some View {         Button("Show sheet") {             showSheet = true         }.sheet(isPresented: $showSheet) {             VStack(spacing: 0) {                 Text("Title")                 Divider()                 Text("Line 1")                 Text("Line 2. Blah blah blah blah.")                 Divider()                 HStack {                     Button("Cancel") { showSheet = false }                     Divider()                     Button("OK") { showSheet = false }                 }.fixedSize(horizontal: false, vertical: true)             }             .frame(minWidth: 0, minHeight: 0)             .fixedSize()         }     } } The result:
1
0
626
Sep ’21
Flush Metal rendering when program is paused in LLDB?
I watched a WWDC talk on LLDB, and they showed a nice trick of calling CATransaction.flush() from the debugger, to push changes to a UIView to the screen, even when the program was paused. Is there is a similar thing we can do with Metal? I'm using MTKView, but I can change to a lower level if that's required. The MTKView is paused, so I'm using setNeedsDisplay. As usual, I implement the draw delegate method to encode and commit a command buffer. If I do this from LLDB: metalView.setNeedsDisplay() CATransaction.flush() I can see that causes my draw function to run, but nothing shows up on screen. Is there something else we can do to flush those metal commands to the GPU and see them on screen while stepping through the program with the debugger?
1
0
936
Nov ’21
Full Disk Access, Run and Debug from Xcode?
I'm working on a macOS app that I want to give "Full Disk Access". When I run from Xcode, I get "permission denied" errors when reading a file in my home directory. What can I do so that I can run and debug from Xcode? I dragged the binary from the derived data folder to the System Preferences list for Full Disk Access, but that seems to do nothing.
5
0
3.0k
Feb ’25
UIScrollView does not give touches to subview if drag starts quickly
I have a UIScrollView, and its subview inside needs to respond to some touchesMoved events without scrolling. I've got it mostly working, but with one sticking point that confuses the user: if I touch and quickly move my finger, then the UIScrollView takes the gesture as a scroll, and never calls the touchesBegan, touchesMoved, etc., of its subview. However, if I touch, then pause for a bit, then drag, then things work as intended: the subview gets touchesBegan, touchesMoved, etc., and things are handled without any scrolling. On my UIScrollView, I've set: delaysContentTouches = false canCancelContentTouches = true And I've overrode touchesShouldCancel(in view: UIView). But that does not get called in the case when I quickly drag my finger. Is there something else I need to do?
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
1.7k
Feb ’22
For cursor update events (with NSTrackingArea) how to know if it's coming or going?
I've added an NSTrackingArea to my NSView because I want a certain rectangular area to show a different cursor. As expected, my view gets a call to it's cursorUpdate:(NSEvent*) method, but how do I tell whether it's an "enter" or "leave". - (void)cursorUpdate:(NSEvent *)event { // Do I push or pop my custom NSCursor? } I notice the event.modifierFlags changes from 8 to 9. But I don't see any public enum constants to test that, so I don't know if I can depend on that. The public enum contains stuff like this, in the higher bits. typedef NS_OPTIONS(NSUInteger, NSEventModifierFlags) { NSEventModifierFlagCapsLock = 1 << 16, NSEventModifierFlagShift = 1 << 17, ... The tracking area setup code: NSRect nsRect = ... NSTrackingAreaOptions options = NSTrackingCursorUpdate | NSTrackingActiveInKeyWindow; NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect: nsRect options: options owner: owner userInfo: userInfo]; [myView addTrackingArea: trackingArea];
Topic: UI Frameworks SubTopic: AppKit Tags:
1
0
1.5k
Oct ’22
Important item in Keychain seems to have disappeared (after years)
I had the following code in a program that I used to encrypt some important files. I haven't run it in a few years. It used to work, and now it seems the password is mysteriously gone from my Keychain! The return value is now errSecItemNotFound. I'm upset with myself for not backing up the key/password somewhere else. Is there anywhere this could be hiding? Did Apple move it somewhere? I know they created this "Passwords" app in recent years, but I don't see anything in there with the "account" string I used. I run the app from Xcode, so maybe it is in the "container" data somewhere? I do see keychain files under ~/Library. Maybe there is a way to look through old Time Machine backups. Ug. So stressful. Just looking for pointers on where the data might be, and why it might have disappeared. Unfortunately it was not a "guessable" password, it was a generated 256 bit key, base64 encoded. Perhaps I could crack that with brute force if I'm determined enough... public static func queryGenericPasswordAsString(account: String) throws -> String { let query: [String: Any] = [kSecClass as String: kSecClassGenericPassword, kSecMatchLimit as String: kSecMatchLimitOne, kSecAttrAccount as String: account, kSecReturnAttributes as String: true, kSecReturnData as String: true] var item: CFTypeRef? let status = SecItemCopyMatching(query as CFDictionary, &item) guard status != errSecItemNotFound else { throw KeychainError.noPassword } ... }
8
0
357
Mar ’25
CustomMetalView sample uses deprecated functions - update?
The sample code here, has code like: // Create a display link capable of being used with all active displays cvReturn = CVDisplayLinkCreateWithActiveCGDisplays(&_displayLink); But that function's doc says it's deprecated and to use NSView/NSWindow/NSScreen displayLink instead. That returns CADisplayLink, not CVDisplayLink. Also the documentation for that displayLink method is completely empty. I'm not sure if I'm supposed to add it to run loop, or what, after I get it. It would be nice to get an updated version of this sample project and/or have some documentation in NSView.displayLink
2
0
362
Jul ’25
Images in documentation comments not working?
Does anyone use this? I can't get it working. I'm talking about code in normal swift files, not playgrounds.Example:/// ![testdiagram](/Users/me/fullpathto/test-image.png) /// ![test xcode image](http://devimages.apple.com.edgekey.net/assets/elements/icons/128x128/xcode.png) ///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.
3
0
1.9k
Oct ’22
Popping back multiple levels?
I have a UI where you can navigate/push views like this: Root view &gt; List of things &gt; View thing &gt; 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?
3
0
7.5k
Sep ’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
2.1k
Mar ’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
511
Apr ’21