Construct and manage a graphical, event-driven user interface for your macOS app using AppKit.

AppKit Documentation

Post

Replies

Boosts

Views

Activity

Every app crashes if "Help" menu is opened
This might sound strange and but I'd really like to get this resolved. I first though this was the fault of a macos application that I developed. But later I noticed that it is practically applies to every application on the macbook I've got. If I press "Help" in the menu-bar, in any app on my mac. That app crashes. In some apps, it crashes directly, in some, it show a corrupt list first, then crashes. This is how it looks in Safari for example (1 second after pressing "Help"): Here's the stacktrace for Safari: 0 libobjc.A.dylib 0x181319c20 objc_msgSend + 32 1 Shortcut 0x1bd7aca5c -[SCTSearchManager hasNoResults] + 56 2 Shortcut 0x1bd7aea78 -[SCTSearchManager selectRowAfterTargetingItem:withMenu:] + 36 3 Shortcut 0x1bd7abdc4 SCTHelpMenuHandler + 508 4 HIToolbox 0x18afbb3a4 DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) + 1092 5 HIToolbox 0x18afba828 SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) + 356 6 HIToolbox 0x18afba6b8 SendEventToEventTargetWithOptions + 44 7 HIToolbox 0x18b188878 SendItemEvent(MenuSelectData*, unsigned int, MenuData*, unsigned short) + 308 8 HIToolbox 0x18b050f10 UpdateMenuViewFocus(MenuSelectData*, MenuData*, short, short) + 568 9 HIToolbox 0x18b04be28 ViewFocusHandler(OpaqueEventHandlerCallRef*, OpaqueEventRef*, void*) + 520 10 HIToolbox 0x18afbb3a4 DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) + 1092 11 HIToolbox 0x18afba828 SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) + 356 12 HIToolbox 0x18afba6b8 SendEventToEventTargetWithOptions + 44 13 HIToolbox 0x18b02f528 HIView::SendSetFocusPart(short, unsigned char, unsigned char, short*) + 248 14 HIToolbox 0x18b02f394 HIView::SetFocusPartInternal(short, unsigned char, unsigned char, short*, short, unsigned char, unsigned char) + 116 15 HIToolbox 0x18b02f14c HIView::SetFocusPart(short, unsigned char, unsigned char, unsigned int, FocusData*) + 240 16 HIToolbox 0x18b02ef90 HIViewSetFocus + 168 17 HIToolbox 0x18b05049c ChooseItem(MenuSelectData*, Rect const*) + 220 18 HIToolbox 0x18b1876e4 TrackMenuCommon(MenuSelectData&, unsigned char*, SelectionData*, MenuResult*, MenuResult*) + 800 19 HIToolbox 0x18b052c0c MenuSelectCore(MenuData*, Point, double, unsigned int, OpaqueMenuRef**, unsigned short*) + 348 20 HIToolbox 0x18b052a00 _HandleMenuSelection2 + 416 21 AppKit 0x184b09918 _NSHandleCarbonMenuEvent + 256 22 AppKit 0x184b0973c _DPSEventHandledByCarbon + 60 23 AppKit 0x1849b7104 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2232 24 Safari 0x1ac42a218 -[BrowserApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 228 25 AppKit 0x1849aaf7c -[NSApplication run] + 464 26 AppKit 0x1849823cc NSApplicationMain + 880 27 Safari 0x1ac791e24 SafariMain + 408 28 dyld 0x18135bf28 start + 2236
0
0
376
Feb ’24
MacOS App crashes when mouse moves over WKWebView, only under Ventura and Sonoma
This is a problem that only exists on MacOS 13 (Ventura) and MacOS 14 (Sonoma). On all earlier versions of MacOS, the existing code works well, and has for many years. I am working on an long-running Objective-C MacOS app (non-sandboxed) that uses WKWebView to display a static web page within a "pane" of a larger NSView. By "pane", I mean the WKWebView might be the only view within the encompassing NSView (thereby occupying all of its space), or it might occupy only one rectangle within it, if the NSView is divided into arbitrary rectangles. (Whether or not the WKWebView takes up the entire surrounding rectangle, or just a section of it, seems irrelevant.) The WKWebView is created offscreen at startup time, and later may become visible under user control. I don't need the displayed web page to permit any interactivity with the user other than scrolling, and I disable Javascript on the page using the WKWebViewConfiguration - which appears to work as intended. I therefore have no need for NSTrackingArea either, and am not using it. It does appear that the WKWebView has one NSTrackingArea by default, but it's not mine. I can remove it programmatically, but that does not appear to make any difference. When the WKWebView is visible, the app will instantly crash as soon as the cursor enters its rectangle. The stack trace shows the error: [_NSTrackingAreaCGViewHelper cursorAreas]: unrecognized selector sent to instance The problem here is that the _NSTrackingAreaCGViewHelper method appears to be something within an Apple internal framework - I can't find discussion of it anywhere on the Internet, or in Apple's developer docs. Same for the selector "cursorAreas" - I can't find any information about it at all. So this is starting to feel like a bug somewhere in Apple's internal framework. I can't understand why it's crashing with a message related to NSTrackingArea (or similar objects), when I'm not using tracking at all, but the "unrecognized selector" error is even more disturbing - I'm not calling the method, and certainly can't control the selector. I can't be sure, but this feels like Apple's error. I'd like to know if there might be a way for me to configure WKWebView to not use tracking at all, thereby eliminating the issue entirely, but I can't find a way to do that other than removing the NSTrackingAreas from the WKWebView, but that's not helping either. Can anyone (especially from Apple) offer any guidance? If it's an Apple bug, I would love to know how to work around it - it's a show-stopper for this app. Thanks in advance...
0
0
491
Feb ’24
TableView.makeView question
Is it possible that I bypass tableView.makeView so that I can create a NSTableCellView on the fly (based on some logics)? func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { if NSTableColumn.identifier.rawValue == "labelColumn" { let myCellView = NSTableCellView() myCellView.textField.strinValue = "label text" return myCellView } else { let complexView = loadFromNib() // of NSTableCellView // populate complexView return complexView } }
0
0
343
Jan ’24
ScreenSaver caching during development on Sonoma
Hi all, I've been playing around with making a screen saver using ScreenSaver.framework and having issues with (what appears to be) macOS caching the previous version of the screensaver until I reboot. I have written a screen saver that works, however if I make some changes to the code, re-archive and reinstall the newly compiled screen saver still presents the old screen saver. I've tried incrementing the build number to no avail. Does anyone have a solution to this? My workflow :- Uninstall and delete all instances of my screen saver. Reboot Open Xcode, compile, re-archive my screen saver. Double-click the archived screen-saver, click to install for this user. Test screensaver -- success! Now, Delete the screensaver by right-click on screensaver in System Settings, "Delete " Make changes to my code, rearchive. Double-click the archived screen-saver, click to install for this user. Test screensaver -- fail! Still shows the old version of the screensaver. Reboot machine Test screensaver -- success! Screensaver now shows the changes I made. Many thanks all.
1
0
773
Jan ’24
Customize NSCollectionView Drop Indicator in custom NSCollectionViewLayout
I've created a custom NSCollectionView layout that is vertical in design and it supports dragging and dropping. However, the drawn drop indicator only is a vertical line in the middle of the inter gap or drop zones specified. Ideally, I'd like for this line to be horizontal, extending the width of the frame rather than the vertical and extending the height. Basically, I am trying to replicate the drop indicator that's used in NSTableView or NSOutlineView. Is there any way to accomplish this?
0
0
405
Jan ’24
Missing mouseUp events
I have a view (custom subclass of NSView) that overrides mouseDown: and mouseUp:. If I double-click the view, I expect to see a sequence of events: mouseDown with clickCount == 1 mouseUp with clickCount == 1 mouseDown with clickCount == 2 mouseUp with clickCount == 2 Usually, that's what happens. But occasionally, the second or both mouse up events don't arrive. That's a problem, because it's my understanding that if you want to handle a double-click, you should be looking for the second mouse up. I am certain that the mouse location is always within the bounds of the view. What could cause this? (Testing on macOS 13.6.4.) Added: I use a subclass of NSApplication, and override nextEventMatchingMask:untilDate:inMode:dequeue: and sendEvent:. The overrides usually just call through to the superclass method. Logging mouse events from these methods, I see that in the problematic cases, the mouse up events are received from the queue, but never sent.
2
0
641
Jan ’24
How do we open "Keyboard Viewer"?
How do we open Keyboard Viewer programatically? I am working on Sonoma Mac Application. I could open "Emoji & Symbols" programatically as follows. NSArray *sources = (__bridge NSArray*)TISCreateInputSourceList(nil, false); TISInputSourceRef keyboardViewer = (__bridge TISInputSourceRef)[sources objectAtIndex: 2]; // "Emoji & Symbols" is the 3rd one. So 2. TISSelectInputSource(keyboardViewer); CFRelease((CFTypeRef)sources); After some searching, Keyboard Viewer could be opened with similiar approach with above in the old previous version of MacOS. I have a strong feeling there is a way to bring up the keyboard because we can bring up "Emoji & Symbols". I mean, why would apple prevent us to show Keyboard Viewer. Any idea?
0
0
350
Jan ’24
Simulate sending key to an NSView on a macOS application
Hello, I am trying to simulate a keystroke inside a macOS application. Here is what i've done: let src = CGEventSource(stateID: CGEventSourceStateID.hidSystemState) let cmd_down = CGEvent(keyboardEventSource: src, virtualKey: 0x38, keyDown: true) let cmd_up = CGEvent(keyboardEventSource: src, virtualKey: 0x38, keyDown: false) cmd_down?.post(tap: .cghidEventTap) cmd_up?.post(tap: .cghidEventTap) macOS is asking me to allow my application on TCC accessibility. This is a global privilege and needs admin rights. And i want to avoid that. Is there an alternative to simulate a key stroke inside my application ? Thanks
2
0
701
Oct ’23
NSTableView.reloadData(forRowIndexes:columnIndexes:) causes wrong subview layout when usesAutomaticRowHeights = true
I have a table view where each row has two labels, one left-aligned and one right-aligned. I would like to reload a single row, but doing so causes the right-aligned label to hug the left-aligned label. Before the reload: After the reload: Reloading the whole table view instead, or disabling automatic row height, solves the issue. Can a single row be reloaded without resorting to these two workaround? class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate { override func loadView() { let tableView = NSTableView() tableView.translatesAutoresizingMaskIntoConstraints = false tableView.dataSource = self tableView.delegate = self tableView.usesAutomaticRowHeights = true let column = NSTableColumn() column.width = 400 tableView.addTableColumn(column) let scrollView = NSScrollView(frame: CGRect(x: 0, y: 0, width: 500, height: 500)) scrollView.translatesAutoresizingMaskIntoConstraints = false scrollView.documentView = tableView view = scrollView Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { _ in print("reload") tableView.reloadData(forRowIndexes: IndexSet(integer: 2), columnIndexes: IndexSet(integer: 0)) // tableView.reloadData() } } func numberOfRows(in tableView: NSTableView) -> Int { return 5 } func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { let cell = NSTableCellView() let textField1 = NSTextField(labelWithString: "hello") textField1.translatesAutoresizingMaskIntoConstraints = false let textField2 = NSTextField(wrappingLabelWithString: "world") textField2.translatesAutoresizingMaskIntoConstraints = false textField2.alignment = .right let stack = NSStackView(views: [ textField1, textField2 ]) stack.translatesAutoresizingMaskIntoConstraints = false stack.distribution = .fill cell.addSubview(stack) NSLayoutConstraint.activate([stack.topAnchor.constraint(equalTo: cell.topAnchor, constant: 0), stack.leadingAnchor.constraint(equalTo: cell.leadingAnchor, constant: 0), stack.bottomAnchor.constraint(equalTo: cell.bottomAnchor, constant: 0), stack.trailingAnchor.constraint(equalTo: cell.trailingAnchor, constant: 0)]) return cell } }
0
0
373
Jan ’24
SwiftUI Emoji Picker - MacOS
Hello, I am developing a multi-platform app, and I need an emoji picker. It should be the same as the emoji selection view in the Reminders App. Reminders App Image: (A button; when pressed calls the MacOS emoji selector, and the emoji selected is linked to a variable). I know you can call the EmojiSelector with NSApp.orderFrontCharacterPalette($variable) However, it only records the variable if you have a working text field linked to the variable. Then, if you edit the text field you can select more than 1 character, a non-emoji, and the emoji popover is not shown under the button. How do I make an emoji selector like the one above. Does it require a textfield for the selected emoji to be linked to a variable. If it does, can the text field be: Not Viewable and in a ZStack under the button Only editable by the emoji selector Replace the current emoji when another is selected Sorry if my question is lengthy. I have everything else in my app ready, and want to release it to the app store (it will be free). Thank you for any help, Dev_Pro
0
3
937
Jan ’24
HIToolbox crashes on macOS
Lately, we are getting a few crash reports ending up with: NSRangeException *** -[NSConcreteTextStorage attribute:atIndex:longestEffectiveRange:inRange:]: Range or index out of bounds The full stack trace is: Thread 0 Crashed: 0 CoreFoundation 0xfff0177080a6 __exceptionPreprocess 1 libobjc.A.dylib 0xfff016dcd231 objc_exception_throw 2 UIFoundation 0xfff020adce02 -[NSConcreteTextStorage attribute:atIndex:longestEffectiveRange:inRange:] 3 AppKit 0xfff01f051947 __55-[NSTextInputContext handleTSMEvent:completionHandler:]_block_invoke_7.611 4 AppKit 0xfff01f05178e __55-[NSTextInputContext handleTSMEvent:completionHandler:]_block_invoke_2.605 5 AppKit 0xfff01f04d137 -[NSTextInputContext tryHandleTSMEvent_attributedString_attributedSubstringForProposedRange_withContext:dispatchCondition:dispatchWork:dispatchFurtherCondition:dispatchFurtherWork:continuation:] 6 AppKit 0xfff01e4d37c7 -[NSTextInputContext handleTSMEvent:completionHandler:] 7 AppKit 0xfff01e4d29c8 _NSTSMEventHandler 8 HIToolbox 0xfff02c78f702 DispatchEventToHandlers 9 HIToolbox 0xfff02c78eb4e SendEventToEventTargetInternal 10 HIToolbox 0xfff02c78e9ed SendEventToEventTargetWithOptions 11 HIToolbox 0xfff02c7e7da0 SendTSMEvent_WithCompletionHandler 12 HIToolbox 0xfff02c9404bf __SendTextInputEvent_WithCompletionHandler_block_invoke 13 HIToolbox 0xfff02c93ee07 SendTextInputEvent_WithCompletionHandler 14 HIToolbox 0xfff02c9a06b4 -[IMKInputSession _postEvent:completionHandler:] 15 HIToolbox 0xfff02c9b3997 -[IMKInputSession do_coreAttributesFromRange_postEventLoopWithContext:initBlockEach:postEventCompletionEach:whileConditionBlock:finalCompletion:] 16 HIToolbox 0xfff02c9b4710 __78-[IMKInputSession _coreAttributesFromRange:whichAttributes:completionHandler:]_block_invoke_10 17 HIToolbox 0xfff02c7fc58c DispatchEventToHandlers 18 AppKit 0xfff01f051707 __55-[NSTextInputContext handleTSMEvent:completionHandler:]_block_invoke_7.599 19 AppKit 0xfff01f051412 __55-[NSTextInputContext handleTSMEvent:completionHandler:]_block_invoke_2.593 20 AppKit 0xfff01f04d137 -[NSTextInputContext tryHandleTSMEvent_attributedString_attributedSubstringForProposedRange_withContext:dispatchCondition:dispatchWork:dispatchFurtherCondition:dispatchFurtherWork:continuation:] 21 AppKit 0xfff01e4d37c7 -[NSTextInputContext handleTSMEvent:completionHandler:] 22 AppKit 0xfff01e4d29c8 _NSTSMEventHandler 23 HIToolbox 0xfff02c78f702 DispatchEventToHandlers 24 HIToolbox 0xfff02c78eb4e SendEventToEventTargetInternal 25 HIToolbox 0xfff02c78e9ed SendEventToEventTargetWithOptions 26 HIToolbox 0xfff02c7e7da0 SendTSMEvent_WithCompletionHandler 27 HIToolbox 0xfff02c9404bf __SendTextInputEvent_WithCompletionHandler_block_invoke 28 HIToolbox 0xfff02c93ee07 SendTextInputEvent_WithCompletionHandler 29 HIToolbox 0xfff02c9a06b4 -[IMKInputSession _postEvent:completionHandler:] 30 HIToolbox 0xfff02c9b3997 -[IMKInputSession do_coreAttributesFromRange_postEventLoopWithContext:initBlockEach:postEventCompletionEach:whileConditionBlock:finalCompletion:] 31 HIToolbox 0xfff02c9b39fe __145-[IMKInputSession do_coreAttributesFromRange_postEventLoopWithContext:initBlockEach:postEventCompletionEach:whileConditionBlock:finalCompletion:]_block_invoke 32 HIToolbox 0xfff02c7fc58c DispatchEventToHandlers 33 AppKit 0xfff01f051707 __55-[NSTextInputContext handleTSMEvent:completionHandler:]_block_invoke_7.599 34 AppKit 0xfff01f051412 __55-[NSTextInputContext handleTSMEvent:completionHandler:]_block_invoke_2.593 35 AppKit 0xfff01f04d137 -[NSTextInputContext tryHandleTSMEvent_attributedString_attributedSubstringForProposedRange_withContext:dispatchCondition:dispatchWork:dispatchFurtherCondition:dispatchFurtherWork:continuation:] 36 AppKit 0xfff01e4d37c7 -[NSTextInputContext handleTSMEvent:completionHandler:] 37 AppKit 0xfff01e4d29c8 _NSTSMEventHandler 38 HIToolbox 0xfff02c78f702 DispatchEventToHandlers 39 HIToolbox 0xfff02c78eb4e SendEventToEventTargetInternal 40 HIToolbox 0xfff02c78e9ed SendEventToEventTargetWithOptions 41 HIToolbox 0xfff02c7e7da0 SendTSMEvent_WithCompletionHandler 42 HIToolbox 0xfff02c9404bf __SendTextInputEvent_WithCompletionHandler_block_invoke 43 HIToolbox 0xfff02c93ee07 SendTextInputEvent_WithCompletionHandler 44 HIToolbox 0xfff02c9a06b4 -[IMKInputSession _postEvent:completionHandler:] 45 HIToolbox 0xfff02c9b3997 -[IMKInputSession do_coreAttributesFromRange_postEventLoopWithContext:initBlockEach:postEventCompletionEach:whileConditionBlock:finalCompletion:] It mostly affects our macOS 14 users who are from China, Hong Kong, and Taiwan - using weird locales most probably. Is anyone having similar problems?
0
1
477
Jan ’24
TextKit 2: edits make duplicate text elements
I'm having an issue with a TextKit2 NSTextView (AppKit). In my subclass's keyDown, I'm doing a bit of manipulation of the textStorage but it seems that if I try to alter any part of the textStorage where a text paragraph and accompanying fragment have already been created, I then get duplicate paragraphs and fragments. For example, say I want to insert new text at the end of an existing paragraph. I've tried: Inserting a new attr string (with attrs matching the preceding text) at the end of the existing paragraph text Replacing the existing paragraph text with a new attr string that includes the new text First deleting the existing paragraph text and then inserting the new full attr string including the new text I am wrapping those edits in a textContentStorage.performEditingTransaction closure. But in all cases, it seems that TextKit 2 wants to create new NSTextParagraph and NSTextFragment objects and doesn't remove the old ones, resulting in duplicate elements in my UI. Some sample code: let editLocation = editRange.location guard editLocation > 0 else { break } let attrs = textStorage.attributes(at: editLocation, effectiveRange: nil) // paragraphStartLocation is in an NSAttributedString extension not shown guard let paragraphStartLoc = textStorage.paragraphStartLocation(from: editLocation) else { assertionFailure(); return } var paragraphRange = NSRange(location: paragraphStartLoc, length: editLocation - paragraphStartLoc + 1) var fullParagraph = textStorage.attributedSubstring(from: paragraphRange).string fullParagraph += newText let newAttrStr = NSAttributedString(string: fullParagraph, attributes: attrs) textContentStorage.performEditingTransaction { textStorage.deleteCharacters(in: paragraphRange) textStorage.insert(newAttrStr, at: paragraphStartLoc) }
1
1
690
Jan ’24
GridView addRow height problem
I am trying to add rows to GridView and not able to get expected row height correctly. override func viewDidLoad() { super.viewDidLoad() // Remove the row in IB designer gridView.removeRow(at: 0) let image = NSImage(named: NSImage.colorPanelName)! //image.size = NSMakeSize(80, 80) let imageView = NSImageView(image: image) imageView.imageFrameStyle = .grayBezel imageView.imageScaling = .scaleAxesIndependently imageView.frame = NSMakeRect(0, 0, 80, 80) let label = NSTextField(labelWithString: "test text") let row = gridView.addRow(with: [imageView, label]) row.height = 80 } What was wrong with my code?
5
0
767
Dec ’23
Issue with delaysPrimaryMouseButtonEvents and NSClickGestureRecognizer
I have an NSTextView where I am getting the current position in the text when the textview is clicked. For this, I am using the NSClickGestureRecognizer which calls a selector that grabs the click position from the .location method of the recognizer. It works as expected however the issue I have is that the click doesn't get recognized by the textView so the insertion point cursor doesn't update in the text view. The actual caret position is updated as if I start typing, the text goes where I last clicked even though the insertion point cursor may be somewhere else. The documentation states that by default, the delaysPrimaryMouseButtonEvents is set to true when using the recognizer with states that the default event will only trigger on gesture failure which isn't what I want as I always want the default event to pass through so I set it to false when initializing the recognizer. What happens when I do this is that the default even goes through but the gesture method is never called. If I remove that, it triggers the gesture method but doesn't pass the event through. It's pretty easy to replicate. Just create a new project with an NSTextView, and use the following ViewController code; class ViewController: NSViewController, NSTextViewDelegate { @IBOutlet var textView: NSTextView! { didSet { let singleClickGesture = NSClickGestureRecognizer(target: self, action: #selector(singleClickGesture(_:))) singleClickGesture.numberOfClicksRequired = 1 // single //If delaysPrimaryMouseButtonEvents set to true or omitted, textView never sets insertion point cursor nor clears any selected text // but singleClickGesture runs every time //If delaysPrimaryMouseButtonEvents set to false, textView sets insertion point cursor every time // but singleClickGesture never runs // I need the singleClickGesture to run then set the insertion point (Cursor Flashing) singleClickGesture.delaysPrimaryMouseButtonEvents = false singleClickGesture.delegate = self textView.addGestureRecognizer(singleClickGesture) textView.delegate = self textView.font = NSFont.systemFont(ofSize: CGFloat(16.0)) self.textView.isSelectable = true } } override func viewDidLoad() { super.viewDidLoad() textView.string = """ This is a block of text I will insert into the text view. It will have multiple lines and will be enough text to reproduce the issue. """ } @objc func singleClickGesture(_ recognizer: NSClickGestureRecognizer) { print("User clicked in textView") if recognizer.state == .ended { let caretLocation = recognizer.location(in: textView) print("Caret location is: \(caretLocation)") let cursorPosition = textView.characterIndexForInsertion(at: caretLocation) print("Cursor position is \(cursorPosition)") } } } extension ViewController: NSGestureRecognizerDelegate { } I've been playing around with this for some time and can't get it to work as I need. If anyone has any suggestion, I would love to hear them. Thx
0
0
396
Dec ’23
NSView content disappears before animation starts on Sonoma
Note: This does not happen on MacOS 13 and older. I have a NSView (parent) and multiple subviews (child nsviews). When I animate the frame of the subviews ex: [[view animator] setFrame:frame] to move them outside the parent view's frame, the contents of the subviews disappear/clipped before the animation starts. This started happening after installing Sonoma. I tried setting clipsToBounds to false and it did not make any difference. Is anyone else seeing this behavior in Sonoma? Why does appkit clip the contents before the animation starts? Is there a way to switch it to "clip after animation ends" ?
0
0
376
Dec ’23
NSToolbarItemGroup has no selection and doesn't send action on click
I currently have a toolbar item group with 3 items, but clicking on any of the items doesn't do anything. Also none of the items appear to be highlighted, not even when manually setting NSToolbarItemGroup.selectedIndex. What am I missing? Setting the action property on the individual items rather than the group makes the items clickable, but still none of them appear to be selected. class ViewController: NSViewController, NSToolbarDelegate { let toolbarItemIdentifier = NSToolbarItem.Identifier("group") let toolbarItemIdentifierItem1 = NSToolbarItem.Identifier("item1") let toolbarItemIdentifierItem2 = NSToolbarItem.Identifier("item2") let toolbarItemIdentifierItem3 = NSToolbarItem.Identifier("item3") override func viewDidAppear() { let toolbar = NSToolbar() toolbar.delegate = self view.window!.toolbar = toolbar view.window!.toolbarStyle = .expanded } func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { return [.flexibleSpace, toolbarItemIdentifier] } func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { return [.flexibleSpace, toolbarItemIdentifier, .flexibleSpace] } func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? { switch itemIdentifier { case toolbarItemIdentifier: let item1 = NSToolbarItem(itemIdentifier: toolbarItemIdentifierItem1) item1.image = NSImage(named: NSImage.addTemplateName)! item1.label = "add" let item2 = NSToolbarItem(itemIdentifier: toolbarItemIdentifierItem2) item2.image = NSImage(named: NSImage.homeTemplateName)! item2.label = "home" let item3 = NSToolbarItem(itemIdentifier: toolbarItemIdentifierItem3) item3.image = NSImage(named: NSImage.pathTemplateName)! item3.label = "path" let group = NSToolbarItemGroup(itemIdentifier: itemIdentifier) group.subitems = [item1, item2, item3] group.selectionMode = .selectOne group.selectedIndex = 0 group.target = self group.action = #selector(selectItem(_:)) return group default: return nil } } @objc func selectItem(_ sender: Any) { print(0) } }
0
0
472
Dec ’23
Dynamic font size for NSTextField on macOS
On iOS I can create a UIFont that automatically adapts to the font size chosen in the Settings app by the user: label.font = UIFont.preferredFont(forTextStyle: .body) label.adjustsFontForContentSizeCategory = true (Copy-pasted from here.) I couldn't find a similar API for macOS. In the Accessibility settings I can change the font size and some apps react to it, like System Settings and Finder automatically increase the labels. Is there a way to create NSFont or NSTextField that automatically adapts to the chosen font size?
0
0
472
Dec ’23
Obscure assertion crash in com.apple.NSScrollingConcurrentVBLMonitor thread
I have received a few crash reports for my app "Find Any File" with an assertion failure as follows: assertion failure: "displayTiming != ((void *)0)" -> %lld Googling this turns up nothing, though. I wonder if someone has some insight into why this might happen, and how to prevent it. One reporting user suggests that it happens when my app shows a very long list of items in an NSTableView (>10000 elements). I have 4 reports from 3 users, and the main thread is doing something related to the table view each time, though not the same (the few other threads are all idle): Crash 1, in macOS 14.0 (23A344: Thread 0:: Dispatch queue: com.apple.main-thread 0 libobjc.A.dylib 0x182c69400 objc_msgSend + 0 1 AppKit 0x186f15400 -[CALayer(NSViewVisibleRect) NS_viewVisibleRectDidChange] + 40 2 AppKit 0x186900e10 NSViewHierarchyInvalidateVisibleRect + 276 3 AppKit 0x186900db0 NSViewHierarchyInvalidateVisibleRect + 180 4 AppKit 0x186900db0 NSViewHierarchyInvalidateVisibleRect + 180 5 AppKit 0x186900db0 NSViewHierarchyInvalidateVisibleRect + 180 6 AppKit 0x186900db0 NSViewHierarchyInvalidateVisibleRect + 180 7 AppKit 0x186900db0 NSViewHierarchyInvalidateVisibleRect + 180 8 AppKit 0x1869990e0 -[NSView translateOriginToPoint:] + 164 9 AppKit 0x186984108 -[NSClipView _immediateScrollToPoint:] + 420 10 AppKit 0x186983eb8 -[NSClipView scrollToPoint:] + 184 11 AppKit 0x186998d80 -[NSScrollView scrollClipView:toPoint:] + 84 12 AppKit 0x1869448dc -[NSClipView _scrollTo:animateScroll:flashScrollerKnobs:] + 480 13 AppKit 0x186b65b24 __62-[NSScrollingBehaviorConcurrentVBL _stopGestureScrollTracking]_block_invoke + 192 14 AppKit 0x186e6a6e8 ___NSMainRunLoopPerformBlockInModes_block_invoke + 44 15 CoreFoundation 0x18310b8c0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 28 Crash 2, in macOS 14.1.1 (23B81): Thread 0:: Dispatch queue: com.apple.main-thread 0 CoreFoundation 0x18ba401f4 DYLD-STUB$$_Block_object_assign + 0 1 libsystem_blocks.dylib 0x18b506118 _call_copy_helpers_excp + 80 2 libsystem_blocks.dylib 0x18b505c68 _Block_copy + 376 3 libdispatch.dylib 0x18b641c7c _dispatch_Block_copy + 32 4 libdispatch.dylib 0x18b658df0 _dispatch_source_set_handler + 92 5 CoreFoundation 0x18b99e1e4 __CFRunLoopCopyMode + 540 6 CoreFoundation 0x18b8b7458 CFRunLoopAddObserver + 220 7 AppKit 0x18f0a687c _PerfAddRunLoopObserver + 192 8 AppKit 0x18f87cd60 -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 368 9 AppKit 0x18f323318 -[_NSScrollingConcurrentEventMonitor startMonitoring] + 380 10 AppKit 0x18f321df8 -[NSScrollingBehaviorConcurrentVBL _scrollView:trackGestureScrollWithEvent:] + 884 11 AppKit 0x18f2e67f8 -[NSScrollingBehaviorConcurrentVBL scrollView:scrollWheelWithEvent:] + 512 12 AppKit 0x18f241770 forwardMethod + 252 13 AppKit 0x18f2e62a0 -[NSView scrollWheel:] + 408 14 AppKit 0x18f241770 forwardMethod + 252 15 AppKit 0x18f2e62a0 -[NSView scrollWheel:] + 408 16 AppKit 0x18f241770 forwardMethod + 252 17 AppKit 0x18f2e62a0 -[NSView scrollWheel:] + 408 18 AppKit 0x18f241770 forwardMethod + 252 19 AppKit 0x18f2e62a0 -[NSView scrollWheel:] + 408 20 AppKit 0x18fc45880 -[NSCollectionView scrollWheel:] + 180 21 AppKit 0x18f241770 forwardMethod + 252 22 AppKit 0x18f241770 forwardMethod + 252 23 AppKit 0x18f2e62a0 -[NSView scrollWheel:] + 408 24 AppKit 0x18f241770 forwardMethod + 252 25 AppKit 0x18f2e62a0 -[NSView scrollWheel:] + 408 26 AppKit 0x18f241770 forwardMethod + 252 27 AppKit 0x18f2e62a0 -[NSView scrollWheel:] + 408 28 AppKit 0x18f1d27b0 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 652 As you can see, there's no code of mine involved at the time of crash. The other (and older) reports are similar, in macOS 13.6.1 and macOS 13.1. All four happened on ARM architecture (which may not be significant due to small number of samples). Memory use of app was not critical (in one case it was about 9 GB total, in others below 4 GB). The "Binary Images" section only lists Apple libs, apart from my app's. So, there seems to be no 3rd party ext involved. I've attached a full report as well. Full report of Crash 1
1
0
772
Dec ’23