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

AppKit Documentation

Post

Replies

Boosts

Views

Activity

Weird problem of NSTableView with auto layout
I have had this issue for a long time. If I configure any auto layout constraints in TableViewCell, I get extremely weird layout behavior in IB designer; however, layout is completely good during runtime. For example, with a completely new project and a single NSTableView on the main view, I get: If I resize main view, the tableview won't get resized Every time I reopen the project, the tableview would shrink by height. It seems the shrinked height is doubled every time. For example, in the following screenshot, the gap is 56. Next reopen will double the gap to 112. Is this a known bug? I would want to file bug report at https://feedbackassistant.apple.com.
1
1
461
Nov ’23
ArrayController is nil at Runtime after awakeFromNib
Hello, here is the block where arrayController is nil : { NSData * data; NSError * error; Class klass; if(_arrayController != nil) // nil ! { selected = [_arrayController selectedObjects]; arranged = [_arrayController arrangedObjects]; if([selected count] > 0) { _currentObject = [selected objectAtIndex:0]; if(_currentObject != nil) { data = [_currentObject valueForKey:kVrRoot]; klass = [NSMutableDictionary class]; _vrRoot = [NSKeyedUnarchiver unarchivedObjectOfClass:klass fromData:data error:&error]; }else { _vrRoot = [NSMutableDictionary new]; data = [NSKeyedArchiver archivedDataWithRootObject:_vrRoot requiringSecureCoding:YES error:&error]; } } } } I use this for years so I don't no what's wrong.
2
0
560
Nov ’23
Xcode downloads client crash reports for [CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]
Xcode contains several crash reports downloaded from users of my app. Thread 0 apparently crashes at [CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink], but there's not a single stacktrace line that contains code within my app, so I have no idea what this means or how to reproduce it. What could cause such a crash? Code Type: X86-64 (Native) Parent Process: launchd [1] User ID: 501 ... OS Version: macOS 14.0 (23A344) ... Crashed Thread: 0 Exception Type: EXC_BAD_INSTRUCTION (SIGILL) Exception Codes: 0x0000000000000001, 0x0000000000000000 Termination Reason: Namespace SIGNAL, Code 4 Illegal instruction: 4 Terminating Process: exc handler [1920] Thread 0 Crashed: 0 AppKit 0x00007ff81c3730c1 -[NSApplication _crashOnException:] + 289 (NSApplication.m:7290) 1 AppKit 0x00007ff81c175ea5 __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke + 853 (NSCATransaction.m:98) 2 AppKit 0x00007ff81cc43339 ___NSRunLoopObserverCreateWithHandler_block_invoke + 41 (AppKit_Internal.h:760) 3 CoreFoundation 0x00007ff818a13836 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 (CFRunLoop.c:1789) 4 CoreFoundation 0x00007ff818a1375a __CFRunLoopDoObservers + 493 (CFRunLoop.c:1902) 5 CoreFoundation 0x00007ff818a12cdc __CFRunLoopRun + 850 (CFRunLoop.c:2946) 6 CoreFoundation 0x00007ff818a12372 CFRunLoopRunSpecific + 557 (CFRunLoop.c:3420) 7 HIToolbox 0x00007ff82327e9d9 RunCurrentEventLoopInMode + 292 (EventLoop.c:455) 8 HIToolbox 0x00007ff82327e616 ReceiveNextEventCommon + 201 (EventBlocking.c:311) 9 HIToolbox 0x00007ff82327e531 _BlockUntilNextEventMatchingListInModeWithFilter + 66 (EventBlocking.c:171) 10 AppKit 0x00007ff81c01a0c5 _DPSNextEvent + 880 (CGDPSReplacement.m:806) 11 AppKit 0x00007ff81c90b150 -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1304 (appEventRouting.m:410) 12 AppKit 0x00007ff81c00b63a -[NSApplication run] + 603 (NSApplication.m:3488) 13 AppKit 0x00007ff81bfdf670 NSApplicationMain + 816 (NSApplication.m:10105) 14 MyApp 0x0000000100627071 main + 129 (main.swift:12) 15 dyld 0x00007ff8185b03a6 start + 1942 (dyldMain.cpp:1269) Thread 1: 0 libsystem_kernel.dylib 0x00007ff8188f9a2e mach_msg2_trap + 10 1 libsystem_kernel.dylib 0x00007ff818907e4a mach_msg2_internal + 84 (mach_msg.c:201) 2 libsystem_kernel.dylib 0x00007ff818900b6e mach_msg_overwrite + 653 (mach_msg.c:0) 3 libsystem_kernel.dylib 0x00007ff8188f9d1f mach_msg + 19 (mach_msg.c:323) 4 CoreFoundation 0x00007ff818a14475 __CFRunLoopServiceMachPort + 143 (CFRunLoop.c:2624) 5 CoreFoundation 0x00007ff818a12ee5 __CFRunLoopRun + 1371 (CFRunLoop.c:3007) 6 CoreFoundation 0x00007ff818a12372 CFRunLoopRunSpecific + 557 (CFRunLoop.c:3420) 7 AppKit 0x00007ff81c1773e0 _NSEventThread + 122 (NSEvent.m:5493) 8 libsystem_pthread.dylib 0x00007ff818939202 _pthread_start + 99 (pthread.c:904) 9 libsystem_pthread.dylib 0x00007ff818934bab thread_start + 15
0
0
292
Nov ’23
Xcode downloads client crash reports for NSApp.runModalForWindow(_:)
Xcode contains several crash reports downloaded from users of my app. Thread 0 apparently crashes after calling NSApp.runModalForWindow(_:) (within the redacted stacktrace rows 17-19 that are locations in my own code). All the other threads only contain calls to system code. What could cause such a crash? ... Code Type: ARM-64 Parent Process: launchd [1] User ID: 501 ... OS Version: macOS 13.5.2 (22G91) ... Crashed Thread: 0 Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x000000018800c728 Termination Reason: Namespace SIGNAL, Code 5 Trace/BPT trap: 5 Terminating Process: exc handler [61015] Thread 0 Crashed: 0 AppKit 0x000000018800c728 -[NSApplication _crashOnException:] + 240 (NSApplication.m:6808) 1 AppKit 0x0000000187e54a10 __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke + 644 (NSCATransaction.m:98) 2 AppKit 0x0000000188530cfc ___NSRunLoopObserverCreateWithHandler_block_invoke + 64 (AppKit_Internal.h:745) 3 CoreFoundation 0x0000000184b059f0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36 (CFRunLoop.c:1789) 4 CoreFoundation 0x0000000184b058dc __CFRunLoopDoObservers + 532 (CFRunLoop.c:1902) 5 CoreFoundation 0x0000000184b04f14 __CFRunLoopRun + 776 (CFRunLoop.c:2944) 6 CoreFoundation 0x0000000184b044b8 CFRunLoopRunSpecific + 612 (CFRunLoop.c:3418) 7 HIToolbox 0x000000018e356df0 RunCurrentEventLoopInMode + 292 (EventLoop.c:455) 8 HIToolbox 0x000000018e356a80 ReceiveNextEventCommon + 220 (EventBlocking.c:311) 9 HIToolbox 0x000000018e356984 _BlockUntilNextEventMatchingListInModeWithFilter + 76 (EventBlocking.c:171) 10 AppKit 0x0000000187d2b97c _DPSNextEvent + 636 (CGDPSReplacement.m:818) 11 AppKit 0x0000000187d2ab18 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 716 (appEventRouting.m:407) 12 AppKit 0x0000000187f63bd0 -[NSApplication _doModalLoop:peek:] + 216 (NSApplication.m:3469) 13 AppKit 0x0000000187f62ad4 __35-[NSApplication runModalForWindow:]_block_invoke_2 + 56 (NSApplication.m:3516) 14 AppKit 0x0000000187f62a80 __35-[NSApplication runModalForWindow:]_block_invoke + 108 (NSApplication.m:3516) 15 AppKit 0x0000000187f62364 _NSTryRunModal + 100 (NSModal.m:25) 16 AppKit 0x0000000187f62224 -[NSApplication runModalForWindow:] + 292 (NSApplication.m:3516) ... 20 AppKit 0x0000000187ed34cc -[NSApplication(NSResponder) sendAction:to:from:] + 440 (appEventRouting.m:1888) 21 AppKit 0x0000000187ed32e4 -[NSControl sendAction:to:] + 72 (NSControl.m:1459) 22 AppKit 0x0000000187fda170 -[NSTableView _sendAction:to:row:column:] + 116 (NSTableView.m:9022) 23 AppKit 0x0000000187fd8d70 -[NSTableView mouseDown:] + 4224 (NSTableView.m:11191) 24 AppKit 0x0000000187ecdef0 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 3476 (winEventRouting.m:1003) 25 AppKit 0x0000000187e58b2c -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 364 (winEventRouting.m:402) 26 AppKit 0x0000000187e587ec -[NSWindow(NSEventRouting) sendEvent:] + 284 (winEventRouting.m:257) 27 AppKit 0x0000000187e57b30 -[NSApplication(NSEvent) sendEvent:] + 1556 (appEventRouting.m:0) 28 AppKit 0x00000001880a7c48 -[NSApplication _handleEvent:] + 60 (NSApplication.m:3342) 29 AppKit 0x0000000187d1efa0 -[NSApplication run] + 500 (NSApplication.m:3430) 30 AppKit 0x0000000187cf63cc NSApplicationMain + 880 (NSApplication.m:9413) 31 MyApp 0x0000000102980cd0 main + 128 (main.swift:12) 32 dyld 0x00000001846cff28 start + 2236 (dyldMain.cpp:1165) ...
0
0
324
Nov ’23
NSCollectionView drag n drop; Sections are ignored in the drop's IndexPath
I have a doc, xib based project. it has an NSCollectionView, which properly displays the data. including items and section headers. I have drag n drop enabled where I can drop into the collectionView, and I generate a new object. this is NOT a reordering issue (yet) when I drop into the collectionView, if the drop is on top of a HeaderView, the drop is canceled (before it gets to my delegate code.) But more importantly : the Header views are entirely ignored in every step of the drag and drop. the hinting, only ever shows up adjacent to a collectionViewItemView, Never below or above the section header. The drop ALWAYS has a section of zero in its index path. regardless of where the drop is. I tried to override this behavior in both the validate drop and accept drop methods. with a great deal of frustration and struggle I discovered that I cannot compare the placement of my header views, because the frames of those views are all at the base origin point. is this normal behavior? Has anyone else run into this? is there a fix?
0
0
435
Nov ’23
macOS application crashes on clicking app menu or the apple menu in macOS Sonoma
I have a macOS app made with the Electron framework. Ever since I updated to macOS Sonoma, I've been facing a random crash whenever I click on the app menu/apple menu. This is not reproducible but happens quite often. On checking the crash report, I can notice that nil is being provided as an input to __NSPlaceholderDictionary initWithObjects method, but this crash does not happen in macOS Ventura or older versions. Is this due to any new validation added to the above method in macOS Sonoma ? Application Specific Backtrace 0: 0 CoreFoundation 0x000000018c6c08c0 __exceptionPreprocess + 176 1 libobjc.A.dylib 0x000000018c1b9eb4 objc_exception_throw + 60 2 CoreFoundation 0x000000018c5d7fa4 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 728 3 CoreFoundation 0x000000018c5d7ca0 +[NSDictionary dictionaryWithObjects:forKeys:count:] + 52 4 AppKit 0x000000019059d56c __NSSearchFieldCellGetSymbolImageDict_block_invoke + 3616 5 libdispatch.dylib 0x000000018c3c1910 _dispatch_client_callout + 20 6 libdispatch.dylib 0x000000018c3c314c _dispatch_once_callout + 32 7 AppKit 0x000000019059c368 NSSearchFieldCellGetSearchImage + 596 8 AppKit 0x000000018feea85c -[NSSearchFieldCell(NSSearchFieldCell_Local) _adjustSearchButtonCellImages::] + 216 9 AppKit 0x000000018fff2364 -[NSSearchFieldCell initWithCoder:] + 1040 10 AppKit 0x000000018fe6ed74 -[NSClassSwapper initWithCoder:] + 812 11 UIFoundation 0x0000000191161a64 UINibDecoderDecodeObjectForValue + 668 12 UIFoundation 0x00000001911617b0 -[UINibDecoder decodeObjectForKey:] + 312 13 AppKit 0x000000018fe6f2f8 -[NSControl initWithCoder:] + 368 14 AppKit 0x000000018fe6f744 -[NSTextField initWithCoder:] + 72 15 AppKit 0x000000018fff1ef8 -[NSSearchField initWithCoder:] + 52 16 AppKit 0x000000018fe6ed74 -[NSClassSwapper initWithCoder:] + 812 17 UIFoundation 0x0000000191161a64 UINibDecoderDecodeObjectForValue + 668 18 UIFoundation 0x0000000191161bec UINibDecoderDecodeObjectForValue + 1060 19 UIFoundation 0x00000001911617b0 -[UINibDecoder decodeObjectForKey:] + 312 20 AppKit 0x000000018fe30b6c -[NSView initWithCoder:] + 944 21 AppKit 0x000000018fe6e804 -[NSCustomView initWithCoder:] + 76 22 UIFoundation 0x0000000191161a64 UINibDecoderDecodeObjectForValue + 668 23 UIFoundation 0x00000001911617b0 -[UINibDecoder decodeObjectForKey:] + 312 24 AppKit 0x000000018fdfdecc -[NSNibConnector initWithCoder:] + 88 25 AppKit 0x000000018fdfde1c -[NSNibOutletConnector initWithCoder:] + 336 26 UIFoundation 0x0000000191161a64 UINibDecoderDecodeObjectForValue + 668 27 UIFoundation 0x0000000191161bec UINibDecoderDecodeObjectForValue + 1060 28 UIFoundation 0x00000001911617b0 -[UINibDecoder decodeObjectForKey:] + 312 29 AppKit 0x000000018fdfceb8 -[NSIBObjectData initWithCoder:] + 136 30 UIFoundation 0x0000000191161a64 UINibDecoderDecodeObjectForValue + 668 31 UIFoundation 0x00000001911617b0 -[UINibDecoder decodeObjectForKey:] + 312 32 AppKit 0x000000018fdfccd0 loadNib + 264 33 AppKit 0x000000018fdfc34c +[NSBundle(NSNibLoading) _loadNibFile:nameTable:options:withZone:ownerBundle:] + 560 34 AppKit 0x000000018fdfc050 -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 180 35 Shortcut 0x00000001cc34f6d4 -[SCTSearchManager loadNib] + 60 36 Shortcut 0x00000001cc356bb8 -[SCTSearchManager akm_installShortcutView] + 200 37 Shortcut 0x00000001cc3569b4 -[SCTSearchManager menuNeedsUpdate:] + 24 38 CoreFoundation 0x000000018c640780 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 148 39 CoreFoundation 0x000000018c6d49a8 ___CFXRegistrationPost_block_invoke + 88 40 CoreFoundation 0x000000018c6d48f0 _CFXRegistrationPost + 440 41 CoreFoundation 0x000000018c60f434 _CFXNotificationPost + 764 42 Foundation 0x000000018d700c74 -[NSNotificationCenter postNotificationName:object:userInfo:] + 88 43 AppKit 0x0000000190445318 -[NSMenuTrackingSession sendBeginTrackingNotifications] + 204 44 AppKit 0x00000001904495f4 -[NSMenuTrackingSession beginTrackingSession] + 184 45 AppKit 0x00000001904ed170 -[NSMenuBarTrackingSession beginTrackingSession] + 188 46 AppKit 0x00000001904ec1e4 -[NSMenuBarTrackingSession _mouseDownEventHandler:] + 128 47 AppKit 0x00000001904ec14c -[NSMenuBarTrackingSession handleEvent:] + 248 48 AppKit 0x00000001904ec02c __61-[NSMenuBarTrackingSession _addMouseDownEventMonitorIfNeeded]_block_invoke + 192 49 AppKit 0x0000000190020624 _NSSendEventToDequeuingObservers + 252 50 AppKit 0x00000001905f919c -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2260 51 AppKit 0x000000018fe1843c -[NSApplication run] + 476 52 Electron Framework 0x00000001128cefd0 _ZN8electron5fuses45IsLoadBrowserProcessSpecificV8SnapshotEnabledEv + 94056 53 Electron Framework 0x00000001128cd4a0 _ZN8electron5fuses45IsLoadBrowserProcessSpecificV8SnapshotEnabledEv + 87096 54 Electron Framework 0x0000000115494168 _ZN2v88internal20SetupIsolateDelegate13SetupBuiltinsEPNS0_7IsolateEb + 18052380 55 Electron Framework 0x00000001154606ec _ZN2v88internal20SetupIsolateDelegate13SetupBuiltinsEPNS0_7IsolateEb + 17840800
1
0
399
Nov ’23
Browser Password Fields in Monterey+ breaks app hotkey activation
I have an Objective-C App that has worked perfectly until Monterey was released. The app is activated and displays a window when it’s hotkey is typed. The problem is that—starting in Monterey—if the cursor is in an html Password field of ANY website in ANY browser, the app’s window does not display. After many many hours of debugging, I have determined that the problem is that in this case, [NSApp activateIgnoringOtherApps:YES] never activates the app, and that [myWindow makeKeyAndOrderFront:nil] does nothing. In this case, if I display a window using [NSApp runModalForWindow:myWindow], the window does display, but is not key until it is clicked, at which point the app activates. Note that everything works properly with the cursor in any browser field other than a Password field, or in any other app. It also works with the cursor anywhere in MacOS versions 10.12 through 11. Is this is some kind of new security feature? Is this a bug or is there a workaround for this? I there a low-level non-Cocoa way to activate an app?
7
0
550
Nov ’23
[MacOS] Unable to see Drag animations for an NSTextView
Hi, I'm trying to drag an NSTextView from one NSView to another. I'm getting the right events, but the drag animation is not coming up. Subclassed TextView: class MyTextView:NSTextView, NSPasteboardItemDataProvider { func pasteboard(_ pasteboard: NSPasteboard?, item: NSPasteboardItem, provideDataForType type: NSPasteboard.PasteboardType) { NSLog ("Paste") } override func mouseDown(with theEvent: NSEvent) { let pasteboardItem = NSPasteboardItem() pasteboardItem.setDataProvider(self, forTypes: [.string]) let draggingItem = NSDraggingItem(pasteboardWriter: pasteboardItem) draggingItem.setDraggingFrame(self.bounds, contents:.Publisher) beginDraggingSession(with: [draggingItem], event: theEvent, source: self) } override func draggingUpdated(_ sender: NSDraggingInfo) -> NSDragOperation { return NSDragOperation.copy } } Subclassed NSView to receive the drop event: class DropView:NSView { func EnableDrop () { // Registering for drag drop types registerForDraggedTypes([NSPasteboard.PasteboardType.string, NSPasteboard.PasteboardType.URL, NSPasteboard.PasteboardType.multipleTextSelection, NSPasteboard.PasteboardType.color]) } func shouldAllowDrag(_ draggingInfo: NSDraggingInfo) -> Bool { return true } override func draggingEntered(_ sender: NSDraggingInfo) -> NSDragOperation { // To show a copy tooltip during drop return NSDragOperation.copy } override func prepareForDragOperation(_ sender: NSDraggingInfo) -> Bool { return true } override func performDragOperation(_ draggingInfo: NSDraggingInfo) -> Bool { let draggedview = draggingInfo.draggingSource as! NSView NSLog ("Drop received") return true } } When I create my view in the ViewController, I do "myviewobj.EnableDrop()" to receive drop events. However as stated above, I'm not able to see the drag animation happening, however, I do get events for it.
0
0
302
Nov ’23
Why fonts loaded using CoreText (CTFont) behave different than loaded using AppKit (NSFont)?
I tried to load font using CTFontCreateWithFontDescriptor() and it behaves differently than loaded using NSFont(). Let's say the goal is to load font using CoreText that is exactly the same as using AppKit. NSTextField If I use them in NSTextField text offsets and rendering do not match. let familyName = "Helvetica" let fontSize: CGFloat = 30 let string = "Hello, World! gÖ,|#" // Load font using AppKit let font1 = NSFont(name: familyName, size: fontSize)! // Load font using CoreText API let font2 = CTFontCreateWithFontDescriptor(CTFontDescriptorCreateWithAttributes([ kCTFontFamilyNameAttribute: familyName, kCTFontSizeAttribute: fontSize, ] as [CFString : Any] as CFDictionary), 0, nil) as NSFont // Setup text fields let field1 = NSTextField() let field2 = NSTextField() field1.setAsLabel() field2.setAsLabel() field1.font = font1 field2.font = font2 field1.stringValue = string field2.stringValue = string NSAttributedString If I use them in NSAttributedString bounding box height of text is different: let bounds1 = NSAttributedString(string: string, attributes: [ .font: font1 ]).boundingRect(with: .infinity) let bounds2 = NSAttributedString(string: string, attributes: [ .font: font2 ]).boundingRect(with: .infinity) print(bounds1) // Prints: (0.0, -7.0, 252.3486328125, 37.0) print(bounds2) // Prints: (0.0, -7.0, 252.3486328125, 31.0) Investigation I compared fonts, font attributes, traits, feature settings, even binary font tables but I didn't find any difference. It seems like there is something inside that alters behaviour. I found that if I add .usesDeviceMetrics option to NSAttributedString bounds getter, it returns the same result but also completely different frame. let bounds1 = NSAttributedString(string: "Hello, World! gÖ,|#", attributes: [.font: font1]).boundingRect(with: .infinity, options: [.usesDeviceMetrics]) let bounds2 = NSAttributedString(string: "Hello, World! gÖ,|#", attributes: [.font: font2]).boundingRect(with: .infinity, options: [.usesDeviceMetrics]) print(bounds1) // Prints: (2.3583984375, -6.6357421875, 249.9609375, 33.837890625) print(bounds2) // Prints: (2.3583984375, -6.6357421875, 249.9609375, 33.837890625) Question How to load a font using CoreText in a way that NSFont does? Minor question: Why does NSTextField set it's frame origin to -2.0? Just extensions I used in code above: extension CGSize { public static var infinity: Self { .init(width: CGFloat.infinity, height: CGFloat.infinity) } } extension NSTextField { func setAsLabel() { translatesAutoresizingMaskIntoConstraints = false isBezeled = false isBordered = false isEditable = false isSelectable = false drawsBackground = false } }
2
0
536
Nov ’23
No proper replacement for LaunchServices functions
Apple deprecated launch service calls like LSCopyAllRoleHandlersForContentType, referring to -[NSWorkspace URLsForApplicationsToOpenContentType:] instead. However all those new NSWorkspace methods do not have the crucial LSRolesMask the launch service calls have. For example, I have code that looks up all alternative shells, and with LSCopyAllRoleHandlersForContentType I could simply provide LSRoleMask.shell to restrict the returned bundle identifiers to shells only. This is not the first time Apple deprecates stuff without a proper replacement and I don't really get it. Every OS update is basically a downgrade. Or is there another way to replicate the old launch service call behavior?
2
1
535
Nov ’23
macOS 14 - NSAttributedString created from HTML displays as "undefined character" glyphs when certain fonts are used
I allow users to choose a font to use throughout the app, then display text using that font in 3 different ways: As the default body font of an HTML document displayed in a WKWebView. Used to create an NSAttributedString then displayed in an NSTextField. Used as the body font of a very small HTML document (2-3 lines), converted to NSAttributedString, then displayed in an NSTextField. My code has been working fine for years, but starting with the release of Sonoma (macOS 14), any text that is converted from HTML to NSAttributedString displays as all "question marks in boxes" for each character. This happens when certain fonts are used. In particular I've seen it with Calibri, Candara, and SF Pro. Calibri and Candara are Microsoft fonts and I think are distributed with MS Office. SF Pro is an Apple font. There could be others; I haven't done an exhaustive check. What I can tell you is that this has been working fine literally until a couple weeks ago when customers began installing macOS 14. If they go into my app and select a different font (such as Arial or Times New Roman) everything works fine. It is only certain fonts that don't work, and those fonts work when used as the body font of an HTML document in WKWebView and when used as the font for a new NSAttributedString. They just don't work if you make a little HTML document with the font selected as the body font, then convert to NSAttributedString. Here's the code that worked up until macOS 14: NSString *htmlString = @"<!DOCTYPE html>" "<html>" "<head>" "<style>" "body { font-family: 'Candara', serif; font-size: 14px; }" "</style>" "</head>" "<body>" "This won't display right." "</body>" "</html>"; NSData *htmlData = [htmlString dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}; NSError *error; NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:htmlData options:options documentAttributes:nil error:&error]; Note the fallback of "serif" — that doesn't matter. you get all undefined characters and the fallback font is not used. It's as if the renderer really believes the font is usable, but it isn't.
1
0
600
Nov ’23
TextKit 1 anti-aliasing on macOS Sonoma
I've run into a very strange bug on macOS Sonoma, and I'm guessing it's caused by TextKit 1/2 compatibility issues. Whenever the caret is drawn on the last line of NSTextView, the anti-aliasing or drawing rect or something changes, causing the text in the current line fragment rect to wiggle up and down. See the example below: (Note that in this image, I'm using custom caret drawing to test that if that would solve something — it didn't.) The effect is more apparent on non-Retina displays, but still present on Retina screens as well. I'm using TextKit 1 because I'm maintaining compatibility with older systems, and can't move away just yet. The behavior can't be reproduced on any other OS than Sonoma. My NSTextView is scaled using scaleUnitSquareToSize but no matter the scale, the issue seems to be present. Text view also has custom input attributes, which includes line height, but drawing doesn't appear to be affected by that. Has anyone else encountered similar issues on Sonoma, and do you have any suggestions on how to proceed with debugging this?
2
0
584
Nov ’23
Document-based Apple App that can run on iOS, iPadOS, and macOS
I am new to developing native Apple apps and must familiarize myself with the Apple development frameworks. I am starting to create a personal document-based Apple App that can run on iOS, iPadOS, and macOS. The document will contain the following: HTML, PDF, images, video, and audio files. So, I think the document format could be HTML. I need the capability to read, edit (WYSIWYG Editor), save, and share documents with other users using the same app. The data is stored in the user's device and iCloud. I need guidance about what Apple framework I should use to edit the documents using WYSIWYG editing principles. I would really appreciate any recommendation you can provide. Many thanks for considering my request. Thank you so much for your attention and participation.
2
0
728
Nov ’23
NSTextView crash with interaction between inserted .link attribute in text storage and NSSpellChecker
I have been getting crash reports from users of my Mac app on Sonoma 14.0 and 14.1 when typing into an NSTextView subclass. The crash logs I have show involvement of the spell-checking system - NSTestCheckingController, NSSpellChecker, and NSCorrectionPanel. The crash is because of an exception being thrown. The throwing method is either [NSString getParagraphStart:end:contentsEnd:forRange:] or [NSTextStorage ensureAttributesAreFixedInRange:]. I have not yet reproduced the crash. I have tried modifying the reference finding process to simply link every word, via NSStringEnumerationByWords. The text view in question recognizes certain things in the entered text and adds hyperlinks to the text while the user is typing. It re-parses and re-adds the links on every key press (via overriding the didChangeText method), on a background thread. From user reports, I have learned that: The crash only occurs on macOS 14.0 and 14.1, not on previous versions The call stack always involves the spell checker, and sometimes involves adding recognized links to the text storage (the call to DispatchQueue.main.async in the code below) The crash stops happening if the user turns off the system spell checker in System Settings -> Keyboard -> Edit on an Input Source -> Correct Spelling Automatically switch The crash does not happen when there are no links in the text view. Here is the relevant code: extension NSMutableAttributedString { func batchUpdates(_ updates: () -> ()) { self.beginEditing() updates() self.endEditing() } } class MyTextView : NSTextView { func didChangeText() { super.didChangeText() findReferences() } var parseToken: CancelationToken? = nil let parseQueue = DispatchQueue(label: "com.myapp.ref_parser") private func findReferences() { guard let storage = self.textStorage else { return } self.parseToken?.requestCancel() let token = CancelationToken() self.parseToken = token let text = storage.string self.parseQueue.async { if token.cancelRequested { return } let refs = RefParser.findReferences(inText: text, cancelationToken: token) DispatchQueue.main.async { if !token.cancelRequested { storage.batchUpdates { var linkRanges: [NSRange] = [] storage.enumerateAttribute(.link, in: NSRange(location: 0, length: storage.length)) { linkValue, linkRange, stop in if let linkUrl = linkValue as? NSURL { linkRanges.append(linkRange) } } for rng in linkRanges { storage.removeAttribute(.link, range: rng) } for r in refs { storage.addAttribute(.link, value: r.url, range: r.range) } } self.verseParseToken = nil } } } } } I've filed this as FB13306015 if any engineers see this. Can anyone
2
0
509
Oct ’23