Created
July 1, 2022 12:14
-
-
Save x1unix/3055ec5a45a2c671c837824f02a2ae8c to your computer and use it in GitHub Desktop.
Swift Playgorund window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AppKit | |
import PlaygroundSupport | |
import SwiftUI | |
@objc protocol _NSWindow { | |
var title: String? { get set } | |
var styleMask: UInt { get set } | |
func setFrame(_ frameRect: NSRect, display flag: Bool) | |
func center() | |
func makeKeyAndOrderFront(_ sender: Any?) | |
} | |
let _NSWindowStyleMaskClosable: UInt = 1 << 1 | |
// A bit more roundabout than it needs to be: see https://bugs.swift.org/browse/SR-4243 | |
let window = unsafeBitCast((NSClassFromString("NSWindow")! as! NSObject.Type).init(), to: _NSWindow.self) | |
window.styleMask |= _NSWindowStyleMaskClosable | |
window.title = "Hello from Swift Playgrounds!" | |
window.setFrame(CGRect(x: 0, y: 0, width: 300, height: 300), display: true) | |
window.center() | |
window.makeKeyAndOrderFront(nil) | |
PlaygroundPage.current.needsIndefiniteExecution = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment