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

AppKit Documentation

Post

Replies

Boosts

Views

Activity

Mac swift Xib based doc app deletes a doc when I make changes and then save it.
I have a Mac doc based app. I have save methods setup (they sort of work... I'm trying to get them up and running) I'm using NSSecureCoding, with NSObjects in Swift. It has been unusually frustrating. I have run into something I find wildly difficult to even explain. I can save a new document that has not been saved yet. it loads as expected. but if I make a change to a doc I have already saved, and save that, ny file gets wiped out. my save code is called, and the app wipes all of the data out of the saved file. The file exists, but it's emptied. it goes from around ~200k in size to 2k in size. there's no error that I have identified. It just wipes my file. So I have NO idea if it's something I did. docs are... unhelpful. internet searches... are unhelpful. this is just one of a number of errors I have to figure out, but it is massively complicating everything else. any ideas welcome.
1
0
437
Nov ’23
NSScrollView + NSTextView. scrolling to a specific word.
I have an interesting challenge, but I do not know where to start. given an NSTextView in an NSScrollView, and enough text in the textView to enable scrolling, how do you determine the location of a single word, and jump to it? we see this sort of behavior in Find panels in Most text editors. So it can be done. additionally, I would very much like to find some kind of predetermined... elements in the text. as a link or an image is not text but can be inline with the text (in Attributed strings) I would like to put an element in the text that is not text, but is targetable and capable of being tagged with some kind of reference. Almost like a bookmark, in which I can scroll to. I have determined that I could use URL Links. But they are so fragile.
1
0
673
Nov ’23
What sets NSTextParagraph.paragraphSeparatorRange and paragraphContentRange
With my continued experiments with TextKit2, I'm trying to figure out what sets the properties paragraphSeparatorRange and paragraphContentRange on a NSTextParagraph. These seem to be computed properties (or at least they cannot be directly set via public API). var paragraph = NSTextParagraph(attributedString: NSAttributedString(string: "It was the best of times.\n")) print("attributes: \(paragraph.attributedString.attributes(at: 0, effectiveRange: nil))") print("paragraphSeparatorRange: \(String(describing: paragraph.paragraphSeparatorRange))") print("paragraphContentRange: \(String(describing: paragraph.paragraphContentRange))") In the above example, both paragraphSeparatorRange and paragraphContentRange are nil. However, when using NSTextLayoutManager/NSTextContentStorage they are set. let layoutManager = NSTextLayoutManager() let container = NSTextContainer(size: NSSize(width: 400, height: 400)) layoutManager.textContainer = container let contentStorage = NSTextContentStorage() contentStorage.textStorage = NSTextStorage(string: "It was the best of times.\n") contentStorage.addTextLayoutManager(layoutManager) layoutManager.enumerateTextLayoutFragments(from: contentStorage.documentRange.location, options: .ensuresLayout) { textLayoutFragment in print("layoutFragment: \(textLayoutFragment)") print("textElement: \(String(describing: textLayoutFragment.textElement))") print("textElement.range: \(String(describing: textLayoutFragment.textElement?.elementRange))") let paragraph = textLayoutFragment.textElement as! NSTextParagraph print("paragraphContentRange: \(String(describing: paragraph.paragraphContentRange))") print("paragraphSeparatorRange: \(String(describing: paragraph.paragraphSeparatorRange))") return true } Would appreciate any ideas on how these values are computed/set. Thanks
1
0
629
Dec ’23
Change text in NSScrollView
Hello, I need to change the text of an NSScrollView at run time, but the command below is not working: ScrViwRegras.documentView?.insertText (rules.retornaTextoRegras()) Where Rules is a struct that has the returnTextoRegras() method that returns the new text. Has anyone had this problem? Xcode 15.0.1 in MacBook Air not iOS), Swift 5, Hugs
0
0
339
Dec ’23
FAULT: <NSRemoteView: 0x14665e360 com.apple.TextInputUI.xpc.CursorUIViewService TUICursorUIViewService> determined it was necessary to configure <TUINSWindow: 0x126706c70> to support remote view vibrancy
This message is logged in Xcode when I start editing a text field in my macOS app. This started appearing in Sonoma. This doesn't happen in Ventura (same Xcode project). Every text field in the app is affected, regardless of the window. What could be the cause of this?
2
3
2.0k
Dec ’23
NSOpenPanel does not work and the application becomes “not responding”.
The code below does not work properly in macos sonoma. I tested it on multiple Macs (mini, m1, intel), but it does not work the same way. (Normal operation in sonoma preview version and previous versions) NSOpenPanel* openPanel = [NSOpenPanel openPanel] Symptoms: When you press the button, the cursor changes to a whirlwind icon. My application and another system service (openAndSavePanelService) become "Not Responding". However, after a few minutes, this condition is resolved and my application returns to normal, but openAndSavePanelService continues to be in the "Not Responding" state. Suppose: Looking at the attached spindump, it is assumed that when openPanel init is called, a problem occurs in the process of communicating with xpc and the system service (openAndSavePanelService) for displaying the dialog box. What I tried: Without creating an instance when pressing the button NSOpenPanel* g_openPanel = [NSOpenPanel openPanel] When the task is attempted in main and the button is pressed, openPanel was attempted with the created instnace, but failed. Tried to work with NSOpenPanel* g_openPanel = [NSOpenPanel openPanel] via dispatch_async(dispatch_get_main_queue(), { ... }) but failed. I found similar questions on forums but they didn't help. https://developer.apple.com/forums/thread/104442?answerId=332068022#332068022 Project environment: Cocoa project Application is agent(UIElement) Hardened Runtime (apple event checked) No Sandbox Network Extension System Extension Deployment Target: 10.9 Could it be a permission issue? Is there anything else worth trying?
5
0
679
Dec ’23
NSDockTilePlugin on Mac AppStore
I wanted to add some dock menu options for my application when it is not running. These dock menu options can be used to launch the application. I came across dock TilePlugin that can be used to add these dock options. But one of the comments in this forum discussion mentions that these Plugins are not allowed if you want ot publish your application in the appStore. Can someone confirm this? If this is true, then Is there some other solution that can be used to add the dock options which appear when the application is not running, and can be used to launch the application? Also do the recent open Files appear using this plugin mechanism?
0
1
391
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)" -&gt; %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 (&gt;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
794
Dec ’23
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
782
Dec ’23
NSTableView is unresponsive when presented in NSApp.runModal(for:)
I've noticed that depending when I call NSApp.runModal(for:), the table view contained in the presented window is unresponsive: it either doesn't scroll at all, or the content only updates after one or two seconds, presumably after the inertial scrolling has ended. In the sample code below I call NSApp.runModal(for:) in 3 different ways: with a direct call inside the callback to perform(_:with:afterDelay:) inside the callback to DispatchQueue.main.async. Only method 2 works. Why? @main class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application let window = NSWindow(contentViewController: ViewController(nibName: nil, bundle: nil)) // 1. doesn't work runModal(for: window) // 2. works // perform(#selector(runModal), with: window, afterDelay: 0) // 3. doesn't work // DispatchQueue.main.async { // self.runModal(for: window) // } } @objc func runModal(for window: NSWindow) { NSApp.runModal(for: window) } } class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate { override func loadView() { let tableView = NSTableView() tableView.addTableColumn(NSTableColumn()) tableView.dataSource = self tableView.delegate = self let scrollView = NSScrollView(frame: CGRect(x: 0, y: 0, width: 500, height: 500)) scrollView.documentView = tableView view = scrollView } func numberOfRows(in tableView: NSTableView) -> Int { return 100 } func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? { return "\(row)" } func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { let cell = NSTableCellView() cell.addSubview(NSTextField(labelWithString: "\(row)")) return cell } }
0
0
415
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
482
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
480
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
386
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
400
Dec ’23
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
708
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
495
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
954
Jan ’24
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
379
Jan ’24