Post

Replies

Boosts

Views

Activity

Printing of NSTextView
I have a document-based macOS app written in Objective-C, and each document window contains a scrollable NSTextView. I know that printing can get complicated if you want to do nice pagination, but is there a quick and dirty way to get basic printing working? As it is, the print panel shows up, but its preview area is totally blank. Here's the current printing part of my NSDocument subclass. - (NSPrintInfo *)printInfo { NSPrintInfo *printInfo = [super printInfo]; [printInfo setHorizontalPagination: NSPrintingPaginationModeFit]; [printInfo setHorizontallyCentered: NO]; [printInfo setVerticallyCentered: NO]; [printInfo setLeftMargin: 72.0]; [printInfo setRightMargin: 72.0]; [printInfo setTopMargin: 72.0]; [printInfo setBottomMargin: 72.0]; return printInfo; } - (void)printDocumentWithSettings:(NSDictionary<NSPrintInfoAttributeKey, id> *)printSettings showPrintPanel:(BOOL)showPrintPanel delegate:(id)delegate didPrintSelector:(SEL)didPrintSelector contextInfo:(void *)contextInfo { NSPrintInfo* thePrintInfo = [self printInfo]; [thePrintInfo setVerticallyCentered: NO ]; NSPrintOperation *op = [NSPrintOperation printOperationWithView: _textView printInfo: thePrintInfo ]; [op runOperationModalForWindow: _docWindow delegate: delegate didRunSelector: didPrintSelector contextInfo: contextInfo]; }
Topic: UI Frameworks SubTopic: AppKit Tags:
2
0
114
1w
Xcode unit test "Creating more than one Application"
When I try to make a unit test target for my macOS app that uses Objective-C, running tests fails, and the debugging log shows a message "Creating more than one Application". If, on the other hand, when I create the unit test target, I select "None" as the target to be tested, and then add all my sources to that target, my tests work. So, I can get my testing done, but I think I must be doing something wrong. By the way, along with the error message, there is a stack crawl: 0 CoreFoundation 0x00007ff8140410aa __exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007ff813b660b7 objc_exception_throw + 48 2 Foundation 0x00007ff814f19bd8 -[NSCalendarDate initWithCoder:] + 0 3 AppKit 0x00007ff817030062 -[NSApplication init] + 1718 4 XCTestCore 0x000000010774b0df -[XCTestDriver _createTestBundlePrincipalClassInstance] + 82 5 XCTestCore 0x0000000107749338 -[XCTestDriver _runTests] + 111 6 XCTestCore 0x000000010770f194 _XCTestMain + 126 7 libXCTestBundleInject.dylib 0x0000000106e8982d __copy_helper_block_e8_32s + 0 8 CoreFoundation 0x00007ff813fc9a91 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12 9 CoreFoundation 0x00007ff813fc99ca __CFRunLoopDoBlocks + 398 10 CoreFoundation 0x00007ff813fc883d __CFRunLoopRun + 898 11 CoreFoundation 0x00007ff813fc7e51 CFRunLoopRunSpecific + 560 12 HIToolbox 0x00007ff81da52f3d RunCurrentEventLoopInMode + 292 13 HIToolbox 0x00007ff81da52b84 ReceiveNextEventCommon + 199 14 HIToolbox 0x00007ff81da52aa8 _BlockUntilNextEventMatchingListInModeWithFilter + 64 15 AppKit 0x00007ff8170689d8 _DPSNextEvent + 858 16 AppKit 0x00007ff817067882 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1214 17 AppKit 0x00007ff817059ef7 -[NSApplication run] + 586 18 AppKit 0x00007ff81702e111 NSApplicationMain + 817 19 PlainCalc 0x00000001057d0a91 main + 65 20 dyld 0x00007ff813b93418 start + 1896
3
0
97
1w
Framework re-export of static library symbols
I'm building an open-source framework called OgreNextMain on macOS, and it statically links to an open-source library called FreeImage. When I run the nm -gU command on the binary within the resulting framework, I see lots of the symbols from FreeImage, but a couple that I wanted to use are missing. I thought, maybe they get stripped if they are not called by OgreNextMain, so I looked into stripping options. The "strip style" in the Xcode build settings for OgreNextMain is set to "debugging symbols". I tried setting the "additional strip flags" build setting to have the "-s" option and the path to a file containing the names of the symbols I want, but that didn't have any effect.
3
0
128
Jul ’25
Where is preferredFilenameExtension getting its information?
If I use [UTType exportedTypeWithIdentifier:] to get one of the types in my app's Info.plist, and then ask for the preferredFilenameExtension of that UTType, I get the wrong extension, i.e., not the first file extension listed for that UTI in my Info.plist. Is this one of those situations where AppKit is looking in some database that can get out of sync with what's actually in the Info.plist?
Topic: UI Frameworks SubTopic: AppKit
2
0
72
Jul ’25
What good is NSBitmapFormatAlphaNonpremultiplied?
If I create a bitmap image and then try to get ready to draw into it, like so: NSBitmapImageRep* newRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nullptr pixelsWide: 128 pixelsHigh: 128 bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES isPlanar: NO colorSpaceName: NSDeviceRGBColorSpace bitmapFormat: NSBitmapFormatAlphaNonpremultiplied | NSBitmapFormatThirtyTwoBitBigEndian bytesPerRow: 4 * 128 bitsPerPixel: 32]; [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithBitmapImageRep: newRep]]; then the log shows this error: CGBitmapContextCreate: unsupported parameter combination: RGB 8 bits/component, integer 512 bytes/row kCGImageAlphaLast kCGImageByteOrderDefault kCGImagePixelFormatPacked Valid parameters for RGB color space model are: 16 bits per pixel, 5 bits per component, kCGImageAlphaNoneSkipFirst 32 bits per pixel, 8 bits per component, kCGImageAlphaNoneSkipFirst 32 bits per pixel, 8 bits per component, kCGImageAlphaNoneSkipLast 32 bits per pixel, 8 bits per component, kCGImageAlphaPremultipliedFirst 32 bits per pixel, 8 bits per component, kCGImageAlphaPremultipliedLast 32 bits per pixel, 10 bits per component, kCGImageAlphaNone|kCGImagePixelFormatRGBCIF10|kCGImageByteOrder16Little 64 bits per pixel, 16 bits per component, kCGImageAlphaPremultipliedLast 64 bits per pixel, 16 bits per component, kCGImageAlphaNoneSkipLast 64 bits per pixel, 16 bits per component, kCGImageAlphaPremultipliedLast|kCGBitmapFloatComponents|kCGImageByteOrder16Little 64 bits per pixel, 16 bits per component, kCGImageAlphaNoneSkipLast|kCGBitmapFloatComponents|kCGImageByteOrder16Little 128 bits per pixel, 32 bits per component, kCGImageAlphaPremultipliedLast|kCGBitmapFloatComponents 128 bits per pixel, 32 bits per component, kCGImageAlphaNoneSkipLast|kCGBitmapFloatComponents See Quartz 2D Programming Guide (available online) for more information. If I don't use NSBitmapFormatAlphaNonpremultiplied as part of the format, I don't get the error message. My question is, why does the constant NSBitmapFormatAlphaNonpremultiplied exist if you can't use it like this? If you're wondering why I wanted to do this: I want to extract the RGBA pixel data from an image, which might have non-premultiplied alpha. And elsewhere online, I saw advice that if you want to look at the pixels of an image, draw it into a bitmap whose format you know and look at those pixels. And I don't want the process of drawing to premultiply my alpha.
3
0
94
Jun ’25
Xcode won't symbolicate .ips crash log
I was my understanding that you're supposed to be able to open a .ips crash log in Xcode and see pretty much what you would see if the app had been running in the debugger when it crashed. But the addresses in my app don't get symbolicated. I opened the .ips in the same project and same version of Xcode that was used to create the app. The .dSym file is around, and I can use it to symbolicate using the atos tool. What am I missing?
3
1
2.2k
Feb ’25
How can a window be visible but not in the onscreen list?
I'm looking at a case where a handler for NSWindowDidBecomeMain gets the NSWindow* from the notification object and verifies that window.isVisible == YES, window.windowNumber &gt; 0 and window.screen != nil. However, window.windowNumber is missing from the array [NSWindow windowNumbersWithOptions: NSWindowNumberListAllSpaces] and from CGWindowListCopyWindowInfo( kCGWindowListOptionOnScreenOnly, kCGNullWindowID ), how can that be? The window number is in the array returned by CGWindowListCopyWindowInfo( kCGWindowListOptionAll, kCGNullWindowID ). I'm seeing this issue in macOS 15, maybe 14, but not 13.
2
0
653
Nov ’24
Problem with event tap permission in Sequoia
I have a Mac app with a background-only helper app that needs to have Accessibility permission in order to use an event tap that can modify events. This has worked OK through Sonoma, but in the Sequoia beta it is failing to create the tap. C code to test the ability to create the event tap: static CGEventRef _Nullable DummyTap(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *userInfo) { return NULL; } static bool CanFilterEvents( void ) { CFMachPortRef thePort = CGEventTapCreate( kCGSessionEventTap, kCGTailAppendEventTap, kCGEventTapOptionDefault, // active filter, not passive listener CGEventMaskBit(kCGEventKeyDown), DummyTap, NULL ); bool madeTap = (thePort != NULL); if (madeTap) { CFMachPortInvalidate( thePort ); CFRelease( thePort ); } return madeTap; } So, on Sequoia, CanFilterEvents returns false in spite of Accessibility permission being granted in System Settings. CGPreflightPostEventAccess also returns false, but AXIsProcessTrusted returns true. I tried making a non-background-only test app, and when that has Accessibility permission, CanFilterEvents, CGPreflightPostEventAccess, and AXIsProcessTrusted all return true. Suggestions on what to try next?
5
0
1k
Jul ’24
How to debug over-release in Objective-C with ARC?
I'm getting a runtime assertion failure like this: "<FFRender3DView 0x616000271580> has reached dealloc but still has a super view. Super views strongly reference their children, so this is being over-released, or has been over-released in the past." Looking at the code, I can't see any strong reference to the view except by its superview, so I can't see how it could be released other than by removal from its superview. My first instinct was to override release and set a breakpoint there, but that's not possible in ARC code.
2
0
861
Jul ’24
Memory leak in ARC conversion, KVO involved
I'm trying to do a piecemeal conversion of a big macOS Objective-C++ code base to use Automatic Reference Counting (ARC), and started with a fairly complex modal dialog. I converted all the classes involved to use ARC. When the dialog closes, the window itself, and some of the controller objects, get deallocated as they should, but some do not. When I look at the memory debugging graph in Xcode, I see a bunch of things of the form NSKVONotifying_MyClassName. Here's an example: It does not look as though any of my objects have strong references to GRMorphController, so what am I to make of this?
2
0
794
Jun ’24
Help interpreting crash report, is KVO involved?
I'm getting occasional crashes, which have not happened while running under a debugger and I haven't figured out how to reproduce. I wonder if anyone can help me glean more information from a crash report. Here's the main part. This particular report if from macOS 14.2 beta, but I've also seen it from 14.1.1. Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000018 Exception Codes: 0x0000000000000001, 0x0000000000000018 VM Region Info: 0x18 is not in any region. Bytes before following region: 140723250839528 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL UNUSED SPACE AT START ---> mapped file 7ffcaf60c000-7ffcd7f48000 [649.2M] r-x/r-x SM=COW ...t_id=b7394f27 Error Formulating Crash Report: PC register does not match crashing frame (0x0 vs 0x1022A3630) Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 <translation info unavailable> 0x1022a3630 ??? 1 libsystem_platform.dylib 0x7ff819d0b393 _sigtramp + 51 2 AppKit 0x7ff81d3549a6 -[NSControl _setWindow:] + 59 3 AppKit 0x7ff81d413c19 -[NSSegmentedControl _setWindow:] + 42 4 AppKit 0x7ff81defd3be __21-[NSView _setWindow:]_block_invoke.391 + 324 5 AppKit 0x7ff81d33a62c -[NSView _setWindow:] + 1886 6 AppKit 0x7ff81defd3be __21-[NSView _setWindow:]_block_invoke.391 + 324 7 AppKit 0x7ff81d33a62c -[NSView _setWindow:] + 1886 8 AppKit 0x7ff81d572d08 -[NSWindow dealloc] + 922 9 MyApp 0x1011b6b81 -[JWWindow dealloc] (in MyApp) (JWWindow.m:37) 10 Foundation 0x7ff81b3d179c _NSKVOPerformWithDeallocatingObservable + 151 11 Foundation 0x7ff81acc6d54 NSKVODeallocate + 150 12 libobjc.A.dylib 0x7ff8199189d7 AutoreleasePoolPage::releaseUntil(objc_object**) + 169 13 libobjc.A.dylib 0x7ff819915cf0 objc_autoreleasePoolPop + 235 14 CoreFoundation 0x7ff819d794a1 _CFAutoreleasePoolPop + 22 15 Foundation 0x7ff81ac869ea -[NSAutoreleasePool drain] + 133 16 AppKit 0x7ff81d315694 -[NSApplication run] + 653 17 AppKit 0x7ff81d2e9662 NSApplicationMain + 816 18 MyApp 0x100ef5034 start (in MyApp) + 52 I can see that it involves deallocating a window as part of draining an autorelease pool, but does the presence of _NSKVOPerformWithDeallocatingObservable mean that KVO is involved somehow? And does the note "PC register does not match crashing frame" tell me anything?
10
0
8.0k
Jun ’24
Make a Finder window open when a disk image mounts
When making a disk image for software distribution, it used to be possible to make a Finder window automatically open when the disk image is mounted, using a command like sudo bless --folder dirPath --openfolder dirPath on a read-write disk image. However, as of Ventura, attempting to do so produces an error message bless: The 'openfolder' option is deprecated and the command fails to do what I want. Disk images that were set up this way in years past continue to work. I suppose I could duplicate a working writable disk image, remove the old contents and put in new contents, but that seems a little hacky. Is there an alternative?
11
0
1.1k
Jun ’24
defaults tool can't handle app group settings?
I have an app group to share settings between a main app and a helper. This is accessed using [[NSUserDefaults alloc] initWithSuiteName: @"FDHC2KMZ6V.com.jwwalker.autopairs.suite"]. What's puzzling me is that if I go to Terminal and enter defaults read FDHC2KMZ6V.com.jwwalker.autopairs.suite it tells me that the domain does not exist. Is this a bug in the defaults tool, or is there some trick I'm missing?
4
1
1.2k
May ’24