Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View kdeda's full-sized avatar

Klajd (Cyde) Deda kdeda

  • id-design, inc.
View GitHub Profile
@kdeda
kdeda / View+NSWindow.swift
Last active March 10, 2024 13:31
Open/Close NSWindow from SwiftUI.View
import SwiftUI
/**
hack to avoid crashes on window close, and remove the window from the
NSApplication stack, ie: avoid leaking window objects
*/
fileprivate final class WindowDelegate: NSObject, NSWindowDelegate {
func windowShouldClose(_ sender: NSWindow) -> Bool {
NSApp.removeWindowsItem(sender)
return true