Post

Replies

Boosts

Views

Activity

Reply to Force NSDocument save panel to select most specific type in format popup button
For instance take the following code: class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { DispatchQueue.main.async { let document = try! NSDocumentController.shared.makeUntitledDocument(ofType: "net.daringfireball.markdown") print(document.fileType!, UTType(document.fileType!)!) NSDocumentController.shared.addDocument(document) document.makeWindowControllers() document.windowControllers[0].window!.title = "Markdown" document.showWindows() } } } And Info.plist: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>UTImportedTypeDeclarations</key> <array> <dict> <key>UTTypeConformsTo</key> <array> <string>public.plain-text</string> </array> <key>UTTypeDescription</key> <string>Markdown</string> <key>UTTypeIcons</key> <dict/> <key>UTTypeIdentifier</key> <string>net.daringfireball.markdown</string> <key>UTTypeTagSpecification</key> <dict> <key>public.filename-extension</key> <array> <string>md</string> <string>mdown</string> <string>markdown</string> <string>text</string> </array> <key>public.mime-type</key> <array> <string>text/markdown</string> <string>text/x-markdown</string> <string>text/x-web-markdown</string> </array> </dict> </dict> </array> <key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeName</key> <string>Plain Text</string> <key>CFBundleTypeRole</key> <string>Editor</string> <key>LSHandlerRank</key> <string>Default</string> <key>LSItemContentTypes</key> <array> <string>public.plain-text</string> </array> <key>NSDocumentClass</key> <string>$(PRODUCT_MODULE_NAME).Document</string> <key>NSUbiquitousDocumentUserActivityType</key> <string>org.desairem.uFocus.OpenDocument</string> </dict> <dict> <key>CFBundleTypeName</key> <string>Markdown</string> <key>CFBundleTypeRole</key> <string>Editor</string> <key>LSHandlerRank</key> <string>Default</string> <key>LSItemContentTypes</key> <array> <string>net.daringfireball.markdown</string> </array> <key>NSDocumentClass</key> <string>$(PRODUCT_MODULE_NAME).Document</string> <key>NSUbiquitousDocumentUserActivityType</key> <string>org.desairem.uFocus.OpenDocument</string> </dict> </array> </dict> </plist> After making sure that the document with the window title Markdown is active, press Command-S to open the default save panel: Plain Text is selected instead of Markdown.
Topic: UI Frameworks SubTopic: AppKit Tags:
Apr ’25
Reply to Change NSTextView Position
I'm interested in adding a margin to a NSTextView by wrapping it in a custom view or adding sibling views, but wasn't able to get the scroll view to keep showing the entire text view. Would you mind sharing your code?
Topic: UI Frameworks SubTopic: AppKit Tags:
Apr ’25
Reply to How to debug Quick Look Preview Extension
Unfortunately this is an ongoing issue and I still don't know how to debug my app's Quick Look Preview Extension. I tried creating a default Xcode project and I can debug it by running the Extension target, selecting Finder in the Xcode dialog, then selecting a file in the Finder and pressing Spacebar. But this doesn't work for my already existing app: the preview just shows a spinning progress indicator, even when using the exact same code in PreviewViewController.swift. The only notable difference I can think of is that my app has an iCloud entitlement. Removing that entitlement and changing the bundle identifiers of the host app and the extension to those used in the sample app get rid of the endless progress indicator... but instead cause an immediate error to be shown at the top of the preview window: "Couldn’t find extension org.domain.problem.QuickLook” I would appreciate any help, as currently the only way to test the Preview Extension is to publish it on the App Store, download it, and see if it behaves as expected, and if not, try something different and repeat the cycle. I created FB17066774.
Topic: App & System Services SubTopic: General Tags:
Apr ’25
Reply to Xcode downloads client crash report with reason "index 0 beyond bounds for empty array" but the stacktraces don't contain any of my app's symbols
Thanks for the suggestions. No user has contacted me about these kinds of issues yet, so logging wouldn't help until someone does. I don't think manipulating threads would help me, since even once I knew what thread causes the crash, I would still be looking for a needle in a haystack, without any information about the kind of function call that caused the crash. My app is an AppKit app which spawns some threads here and there with DispatchQueue. The best (and only feasible) thing, in my opinion, would be for macOS to catch invalid state early and throw a meaningful exception.
Topic: App & System Services SubTopic: General Tags:
Mar ’25
Reply to NSTextView doesn't correctly redraw when deleting text and setting attribute at the same time
I'm still using TextKit1 for backwards compatibility. [quote='831004022, DTS Engineer, /thread/776762?answerId=831004022#831004022'] If the intent of using a custom textContainerInset is to move the text down 8 points, you might be able to achieve it by moving textView down. [/quote] Yes, removing the container inset solves the issue, but I need it. Do you mean moving the scrollView down? That looks ugly. If you mean the textView inside the scrollView, how would I do that?
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’25
Reply to Xcode downloads client crash report with reason "index 0 beyond bounds for empty array" but the stacktraces don't contain any of my app's symbols
It's entirely possible for bugs in your app to cause crashes that don't contain any of your code Ok, but if I don't see any of my code in the stack trace, it can be quite difficult (if not infeasible) to find out what caused the crash. Complex crashes (like this one) happen because your code did one or more things which created the circumstances which lead to the final failure Since I don't have the means of understanding what the final failure was, I would expect that your internal code that caused the final failure would throw some meaningful error that would allow me to understand the issue, or that an error is thrown as soon as your internal code detects that the "circumstances" or preconditions are invalid. Changing your apps implementation so that it includes clear indications of it's actual activity in the crash log. You mean also in case that the user contacts me, right? Otherwise I wouldn't know how to make this visible in the crash report. Making sure you've got a system in place where end users can contact you asking for help How could I make sure of that, or how could I detect that a crash has happened or is about to happen if I have no idea what code causes it?
Topic: App & System Services SubTopic: General Tags:
Mar ’25
Reply to NSTextView doesn't correctly redraw when deleting text and setting attribute at the same time
For some reason the code above doesn't reproduce the issue anymore. Here is new code that seems to work (for now): class ViewController: NSViewController { @IBOutlet var textView: NSTextView! override func viewDidAppear() { textView.textContainerInset = CGSize(width: 0, height: 8) let _ = textView.layoutManager textView.textStorage!.setAttributedString(NSAttributedString(string: "1\n\n2\n3\n4")) textView.textStorage!.addAttribute(.foregroundColor, value: NSColor.labelColor, range: NSRange(location: 0, length: textView.textStorage!.length)) textView.textStorage!.addAttribute(.paragraphStyle, value: paragraphStyle(indent: 100), range: NSRange(location: 0, length: 2)) textView.textStorage!.addAttribute(.paragraphStyle, value: paragraphStyle(indent: 100), range: NSRange(location: 1, length: 2)) textView.textStorage!.addAttribute(.paragraphStyle, value: paragraphStyle(indent: 100), range: NSRange(location: 3, length: 2)) textView.textStorage!.addAttribute(.paragraphStyle, value: paragraphStyle(indent: 100), range: NSRange(location: 5, length: 2)) DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [self] in textView.selectedRange = NSRange(location: 3, length: 0) textView.deleteBackward(nil) textView.textStorage!.beginEditing() textView.textStorage!.addAttribute(.paragraphStyle, value: paragraphStyle(indent: 100), range: NSRange(location: 0, length: 2)) textView.textStorage!.addAttribute(.paragraphStyle, value: paragraphStyle(indent: 100), range: NSRange(location: 2, length: 2)) textView.textStorage!.addAttribute(.paragraphStyle, value: paragraphStyle(indent: 100), range: NSRange(location: 4, length: 2)) textView.textStorage!.addAttribute(.paragraphStyle, value: paragraphStyle(indent: 100), range: NSRange(location: 6, length: 1)) textView.textStorage!.endEditing() } } private func paragraphStyle(indent: Double) -> NSParagraphStyle { let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.firstLineHeadIndent = indent return paragraphStyle } }
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’25
Reply to Crash reports downloaded by Xcode contain impossible call hierarchy
Well, the issue is that the crash report makes it look like a certain method is called which cannot be, and if I ignore that particular frame line, then everything is coherent. So if the explanation, as I assumed, is that merged @objc means that the method was not actually part of the call stack, then everything's ok. I just think that it shouldn't be listed there at all, because it's only confusing.
Mar ’25
Reply to Crash reports downloaded by Xcode contain impossible call hierarchy
This seems to be in fact the same issue that was pointed out in https://developer.apple.com/forums/thread/760029 The output of xcrun crashlog /path/to/crash.crash contains [ 4] 0x0000000100bf81b8 MyApp`MyApp.MainViewController.showSettings(Any) -> () + 428 at MainViewController.swift:132:30 [ 5] 0x0000000100ba252f MyApp`merged @objc MyApp.ConfirmMoveViewController.openSourceInFinder(Any) -> () + 79 merged @objc, if I understand correctly, indicates some compiler optimization. So it would seem that on the way to calling the showSettings method some reused part of the openSourceInFinder method is used, but the crash log makes it appear like openSourceInFinder was genuinely called. Could this perhaps be something to be optimized in how macOS creates crash logs, or is there a way to consistently recognize this?
Mar ’25
Reply to Force NSDocument save panel to select most specific type in format popup button
For instance take the following code: class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ aNotification: Notification) { DispatchQueue.main.async { let document = try! NSDocumentController.shared.makeUntitledDocument(ofType: "net.daringfireball.markdown") print(document.fileType!, UTType(document.fileType!)!) NSDocumentController.shared.addDocument(document) document.makeWindowControllers() document.windowControllers[0].window!.title = "Markdown" document.showWindows() } } } And Info.plist: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>UTImportedTypeDeclarations</key> <array> <dict> <key>UTTypeConformsTo</key> <array> <string>public.plain-text</string> </array> <key>UTTypeDescription</key> <string>Markdown</string> <key>UTTypeIcons</key> <dict/> <key>UTTypeIdentifier</key> <string>net.daringfireball.markdown</string> <key>UTTypeTagSpecification</key> <dict> <key>public.filename-extension</key> <array> <string>md</string> <string>mdown</string> <string>markdown</string> <string>text</string> </array> <key>public.mime-type</key> <array> <string>text/markdown</string> <string>text/x-markdown</string> <string>text/x-web-markdown</string> </array> </dict> </dict> </array> <key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeName</key> <string>Plain Text</string> <key>CFBundleTypeRole</key> <string>Editor</string> <key>LSHandlerRank</key> <string>Default</string> <key>LSItemContentTypes</key> <array> <string>public.plain-text</string> </array> <key>NSDocumentClass</key> <string>$(PRODUCT_MODULE_NAME).Document</string> <key>NSUbiquitousDocumentUserActivityType</key> <string>org.desairem.uFocus.OpenDocument</string> </dict> <dict> <key>CFBundleTypeName</key> <string>Markdown</string> <key>CFBundleTypeRole</key> <string>Editor</string> <key>LSHandlerRank</key> <string>Default</string> <key>LSItemContentTypes</key> <array> <string>net.daringfireball.markdown</string> </array> <key>NSDocumentClass</key> <string>$(PRODUCT_MODULE_NAME).Document</string> <key>NSUbiquitousDocumentUserActivityType</key> <string>org.desairem.uFocus.OpenDocument</string> </dict> </array> </dict> </plist> After making sure that the document with the window title Markdown is active, press Command-S to open the default save panel: Plain Text is selected instead of Markdown.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Apr ’25
Reply to Change NSTextView Position
I'm interested in adding a margin to a NSTextView by wrapping it in a custom view or adding sibling views, but wasn't able to get the scroll view to keep showing the entire text view. Would you mind sharing your code?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Apr ’25
Reply to How to debug Quick Look Preview Extension
Unfortunately this is an ongoing issue and I still don't know how to debug my app's Quick Look Preview Extension. I tried creating a default Xcode project and I can debug it by running the Extension target, selecting Finder in the Xcode dialog, then selecting a file in the Finder and pressing Spacebar. But this doesn't work for my already existing app: the preview just shows a spinning progress indicator, even when using the exact same code in PreviewViewController.swift. The only notable difference I can think of is that my app has an iCloud entitlement. Removing that entitlement and changing the bundle identifiers of the host app and the extension to those used in the sample app get rid of the endless progress indicator... but instead cause an immediate error to be shown at the top of the preview window: "Couldn’t find extension org.domain.problem.QuickLook” I would appreciate any help, as currently the only way to test the Preview Extension is to publish it on the App Store, download it, and see if it behaves as expected, and if not, try something different and repeat the cycle. I created FB17066774.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Apr ’25
Reply to Xcode downloads client crash report with reason "index 0 beyond bounds for empty array" but the stacktraces don't contain any of my app's symbols
Thanks for the suggestions. No user has contacted me about these kinds of issues yet, so logging wouldn't help until someone does. I don't think manipulating threads would help me, since even once I knew what thread causes the crash, I would still be looking for a needle in a haystack, without any information about the kind of function call that caused the crash. My app is an AppKit app which spawns some threads here and there with DispatchQueue. The best (and only feasible) thing, in my opinion, would be for macOS to catch invalid state early and throw a meaningful exception.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Mar ’25
Reply to NSTextView doesn't correctly redraw when deleting text and setting attribute at the same time
I'm still using TextKit1 for backwards compatibility. [quote='831004022, DTS Engineer, /thread/776762?answerId=831004022#831004022'] If the intent of using a custom textContainerInset is to move the text down 8 points, you might be able to achieve it by moving textView down. [/quote] Yes, removing the container inset solves the issue, but I need it. Do you mean moving the scrollView down? That looks ugly. If you mean the textView inside the scrollView, how would I do that?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Mar ’25
Reply to Xcode downloads client crash report with reason "index 0 beyond bounds for empty array" but the stacktraces don't contain any of my app's symbols
It's entirely possible for bugs in your app to cause crashes that don't contain any of your code Ok, but if I don't see any of my code in the stack trace, it can be quite difficult (if not infeasible) to find out what caused the crash. Complex crashes (like this one) happen because your code did one or more things which created the circumstances which lead to the final failure Since I don't have the means of understanding what the final failure was, I would expect that your internal code that caused the final failure would throw some meaningful error that would allow me to understand the issue, or that an error is thrown as soon as your internal code detects that the "circumstances" or preconditions are invalid. Changing your apps implementation so that it includes clear indications of it's actual activity in the crash log. You mean also in case that the user contacts me, right? Otherwise I wouldn't know how to make this visible in the crash report. Making sure you've got a system in place where end users can contact you asking for help How could I make sure of that, or how could I detect that a crash has happened or is about to happen if I have no idea what code causes it?
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Mar ’25
Reply to NSTextView doesn't correctly redraw when deleting text and setting attribute at the same time
For some reason the code above doesn't reproduce the issue anymore. Here is new code that seems to work (for now): class ViewController: NSViewController { @IBOutlet var textView: NSTextView! override func viewDidAppear() { textView.textContainerInset = CGSize(width: 0, height: 8) let _ = textView.layoutManager textView.textStorage!.setAttributedString(NSAttributedString(string: "1\n\n2\n3\n4")) textView.textStorage!.addAttribute(.foregroundColor, value: NSColor.labelColor, range: NSRange(location: 0, length: textView.textStorage!.length)) textView.textStorage!.addAttribute(.paragraphStyle, value: paragraphStyle(indent: 100), range: NSRange(location: 0, length: 2)) textView.textStorage!.addAttribute(.paragraphStyle, value: paragraphStyle(indent: 100), range: NSRange(location: 1, length: 2)) textView.textStorage!.addAttribute(.paragraphStyle, value: paragraphStyle(indent: 100), range: NSRange(location: 3, length: 2)) textView.textStorage!.addAttribute(.paragraphStyle, value: paragraphStyle(indent: 100), range: NSRange(location: 5, length: 2)) DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [self] in textView.selectedRange = NSRange(location: 3, length: 0) textView.deleteBackward(nil) textView.textStorage!.beginEditing() textView.textStorage!.addAttribute(.paragraphStyle, value: paragraphStyle(indent: 100), range: NSRange(location: 0, length: 2)) textView.textStorage!.addAttribute(.paragraphStyle, value: paragraphStyle(indent: 100), range: NSRange(location: 2, length: 2)) textView.textStorage!.addAttribute(.paragraphStyle, value: paragraphStyle(indent: 100), range: NSRange(location: 4, length: 2)) textView.textStorage!.addAttribute(.paragraphStyle, value: paragraphStyle(indent: 100), range: NSRange(location: 6, length: 1)) textView.textStorage!.endEditing() } } private func paragraphStyle(indent: Double) -> NSParagraphStyle { let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.firstLineHeadIndent = indent return paragraphStyle } }
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Mar ’25
Reply to Crash reports downloaded by Xcode contain impossible call hierarchy
Well, the issue is that the crash report makes it look like a certain method is called which cannot be, and if I ignore that particular frame line, then everything is coherent. So if the explanation, as I assumed, is that merged @objc means that the method was not actually part of the call stack, then everything's ok. I just think that it shouldn't be listed there at all, because it's only confusing.
Replies
Boosts
Views
Activity
Mar ’25
Reply to Crash reports downloaded by Xcode contain impossible call hierarchy
This seems to be in fact the same issue that was pointed out in https://developer.apple.com/forums/thread/760029 The output of xcrun crashlog /path/to/crash.crash contains [ 4] 0x0000000100bf81b8 MyApp`MyApp.MainViewController.showSettings(Any) -> () + 428 at MainViewController.swift:132:30 [ 5] 0x0000000100ba252f MyApp`merged @objc MyApp.ConfirmMoveViewController.openSourceInFinder(Any) -> () + 79 merged @objc, if I understand correctly, indicates some compiler optimization. So it would seem that on the way to calling the showSettings method some reused part of the openSourceInFinder method is used, but the crash log makes it appear like openSourceInFinder was genuinely called. Could this perhaps be something to be optimized in how macOS creates crash logs, or is there a way to consistently recognize this?
Replies
Boosts
Views
Activity
Mar ’25