Exercises

  1. Explain the purpose of the assumeInside: flag in the addTrackingRect:owner:userData:assumeInside: method.

  2. Why do you think it is necessary to manually add a tracking rectangle to an NSView in order to have that NSView track the mouse? Why is it necessary to make the tracking view the first responder?

  3. Instead of being added to a separate display list, the annotations could have been integrated with the primary display list. Try to implement the program in this manner. What are the advantages and disadvantages of this approach?

  4. Modify the GraphPaper application so that the displayed formula changes color when you move the mouse over it.

  5. Further modify the GraphPaper application so that you can click the formula and drag it to other locations in the GraphView window.

  6. Investigate the NSFormatter class. Instead of specifying the string values “x:” and “y:” in the mouseMoved: event, create your own NSFormatter that prepends these labels to the floating-point value before it is displayed. Which approach is better — using an NSFormatter or creating the formatted display in the mouseMoved: event?

Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.