an extension that creates and shows a custom dialog in swift

Here is an example of creating and presenting a custom dialog in a macOS extension using Swift:

main.swift
import AppKit

class CustomDialog {
    let alert = NSAlert()
    
    init(title: String, message: String, firstButtonTitle: String, secondButtonTitle: String) {
        alert.messageText = title
        alert.informativeText = message
        alert.addButton(withTitle: firstButtonTitle)
        alert.addButton(withTitle: secondButtonTitle)
    }
    
    func show() {
        alert.runModal()
    }
}

// Example usage:
let dialog = CustomDialog(title: "Custom Dialog", message: "Do you want to proceed?", firstButtonTitle: "Yes", secondButtonTitle: "No")
dialog.show()
575 chars
21 lines

This creates a CustomDialog class with a show() method that presents the dialog as a modal NSAlert. You can customize the title, message, and button titles by passing them into the init method. To use the dialog, simply create an instance and call the show() method.

gistlibby LogSnag