Working with NSResponder

Understanding how the responder chain works is important when building your own views with event handling. In this recipe, you will learn about NSResponder's three most important methods and the sequence in which they are called.

Getting ready

In Xcode, create a new Cocoa Application and name it NSResponder.

How to do it...

  1. In the Xcode project, right-click on the Classes folder and choose Add, then choose New File Under the MacOS X section, select Cocoa Class, then select Objective-C class. Finally, choose NSView in the Subclass of popup. Name the new file MyView.m.
  2. In Xcode, Add the following code to the drawRect: method of the MyView class implementation:
    NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:[self ...

Get Cocoa and Objective-C Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.