Errata: Getting Mouse Events

Hi everyone,

In the chapter Getting Mouse Events, we’re supposed to override three methods of NSResponder: mouseDown(), mouseDragged() and mouseUp().

Starting with Swift 2, the function println() is not available and has to be replaced by print(). But when I made these changes, I got several warnings from Xcode telling me to fix my code. According to Xcode, the print() function should be prefixed by the keyword Swift.

Here’s what I did:

[code]// MARK: - Mouse Events

override func mouseDown(theEvent: NSEvent) {

override func mouseDragged(theEvent: NSEvent) {
Swift.print(“mouseDragged location: (theEvent.locationInWindow)”)

override func mouseUp(theEvent: NSEvent) {
Swift.print(“mouseUp clickCount: (theEvent.clickCount)”)

Sadly, the authors don’t feel the need to update the book for Swift 2, but instead supply a textfile with suggested changes here:

You will also find an errata document with some of the errors of the book (but it’s not even close to being complete).
You’ll have to search through this forum to find answers beyond that.

Hope this helps.


If the mouse event methods are in the MainWindowController.swift, then everything seems to work fine.

p. 298 “…override the methods in DieView:” should be “…override the methods in MainWindowController:”


The right way to do it is in adding ‘Swift.print’ as indicated by tkrajacic and to override the event methods in DieView.

Overriding the event methods in MainWindowController provokes other problems with the code.

Thanks a lot tkrajacic to have found this important detail !!

Using DieView in Swift 3.0 generates some very weird action. Putting the event overrides in MainWindowController works fine.