/*
Save this file with name 'delegate_noMenu.swift'
Create executable in Terminal: swiftc delegate_noMenu.swift -o nm
*/
import Cocoa
class AppDelegate: NSObject, NSApplicationDelegate {
var window:NSWindow!
func buildWnd() {
let _wndW : CGFloat = 400
let _wndH : CGFloat = 300
window = NSWindow(contentRect:NSMakeRect(0,0,_wndW,_wndH),styleMask:[.titled, .closable, .miniaturizable, .resizable], backing:.buffered, defer:false)
window.center()
window.title = "Swift Test Window"
window.makeKeyAndOrderFront(window)
}
func applicationDidFinishLaunching(_ notification: Notification) {
buildWnd()
}
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}
}
let appDelegate = AppDelegate()
// **** main.swift **** //
let app = NSApplication.shared
app.delegate = appDelegate
app.setActivationPolicy(.regular)
app.activate(ignoringOtherApps:true)
app.run()
- Save this file with name 'delegate_noMenu.swift'
- Create an executable in Terminal by using: swiftc delegate_noMenu.swift -o nm
- Manually build a folder system to create an app bundle:
A. Create a folder called 'myApp'.
B. Inside the top folder create a folder called ‘Contents’.
C. Inside ‘Contents’ create two folders called ‘MacOS’ and ‘Resources’.
D. Inside ‘Contents’ folder also add an info.plist file to match the image below. Note that Executable file and Bundle name fields are left blank.
- Add the executable file ’nm’ to the MacOS folder.
- Rename the ‘myApp’ folder to ’nm.app’ which should change the icon and create a double clickable application.
- Hopefully you will not see any menu items in the menu bar and have a functional app. I used MacOS 10.14.6.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…