I didn't really find anything in Apple docs on how to debug my extension using Xcode (so not saying it doesn't exist).
It doesn't exist.
I found a current Stack post on it, with several devs all stuck.
Gotta love the internet, eh?
In 2024 someone said run the Preview Extension, select Finder as the test app, then in a Finder window select a file of the correct type and tap space.
It's hard to debug what someone once said. QuickLook has been redesigned a couple of times. Maybe they were still trying one of the old designs.
The easiest solution is to write a test rig. I was going to include a preview of folders in my new app, but then decided against it. But the QuickLook test rig will be useful in the future. Here's part of that code:
This is view controller for QuickLook:
import Cocoa
import Quartz
class PreviewViewController: NSViewController, QLPreviewingController
{
@IBOutlet weak var folderController: FolderController!
override var nibName: NSNib.Name?
{
return NSNib.Name("PreviewViewController")
}
override func loadView()
{
super.loadView()
// Do any additional setup after loading the view.
}
func preparePreviewOfFile(at url: URL) async throws
{
folderController.url = url
}
override func viewDidLayout()
{
super.viewDidLayout()
folderController.updateLayout(frame: view.frame)
}
}
Here's the AppDelegate for my test rig that manually triggers it:
import Cocoa
import UniformTypeIdentifiers
// The application delegate.
@main
class AppDelegate: NSObject, NSApplicationDelegate
{
var previewWindow: NSWindow!
var previewWindowController: NSWindowController!
var previewViewController: PreviewViewController!
// The application has finished launching.
func applicationDidFinishLaunching(_ aNotification: Notification)
{
previewWindow =
NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 800, height: 600),
styleMask: [.titled, .closable, .resizable, .miniaturizable],
backing: .buffered,
defer: false)
previewWindow.title = "FolderPreview"
previewWindow.center()
previewViewController = PreviewViewController()
previewWindow.contentViewController = previewViewController
previewWindowController = NSWindowController(window: previewWindow)
previewWindowController.showWindow(nil)
previewWindow.makeKeyAndOrderFront(nil)
}
// The application is going to quit.
func applicationWillTerminate(_ aNotification: Notification)
{
// Insert code here to tear down your application
}
// Support secure restorable state.
func applicationSupportsSecureRestorableState(
_ app: NSApplication) -> Bool
{
return true
}
}
extension PreviewViewController
{
// Open a document.
@IBAction
func openDocument(_ sender: Any?)
{
// Allow opening a folder or directory.
var allowedContentTypes = [UTType]()
allowedContentTypes.append(UTType.folder)
allowedContentTypes.append(UTType.directory)
let panel = NSOpenPanel()
panel.allowsMultipleSelection = false
panel.canChooseDirectories = true
panel.allowedContentTypes = allowedContentTypes
if panel.runModal() == .OK
{
if let url = panel.urls.first
{
self.folderController?.url = url
}
}
}
}
Assigning the url property is what does all the work. You'll need to change your allowedContentTypes as appropriate.
Just run the app and choose File > Open.