Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Beeping with NSBeep()

I have never used NSBeep. I've imported AppKit.framework to the project. Under Xcode 8.2 with Swift 3, I have

import AppKit

class AppDelegate: NSObject, NSApplicationDelegate {
    func applicationWillFinishLaunching(_ notification: Notification) {
        NSBeep() 
    }
}

And there's no beeping. What am I doing wrong? Thanks.

like image 946
El Tomato Avatar asked Jan 16 '17 02:01

El Tomato


2 Answers

For Xcode 9.0+, try using NSSound.beep() instead.

like image 167
JohnV Avatar answered Nov 19 '22 09:11

JohnV


Change applicationWillFinishLaunching to applicationDidFinishLaunching. Even better (since some of the other stuff you said is rather weird), start with the built-in template for a Cocoa macOS application and put NSBeep() into the existing applicationDidFinishLaunching implementation. I did that and built-and-ran, and I heard the beep.

like image 3
matt Avatar answered Nov 19 '22 10:11

matt