Skip to Content
Building Cocoa Applications: A Step by Step Guide
book

Building Cocoa Applications: A Step by Step Guide

by Simson Garfinkel, Michael Mahoney
May 2002
Intermediate to advanced
646 pages
18h 57m
English
O'Reilly Media, Inc.
Content preview from Building Cocoa Applications: A Step by Step Guide

PaperController Class Modifications

Now it’s time to finish the PaperController class. To do this, we need to make the following changes to PaperController:

  • Add a method that waits for the user to hit the Return key, gets the new formula that the user has typed, and then sends it to the appropriate Evaluator process.

  • Add a method that gets invoked when there is data from the Evaluator process ready to be displayed in the NSTextView.

  • Terminate the Evaluator process when a MathPaper window is closed.

Creating the NSTextView Delegate

There are many ways to find out when the user hits the Return key. One way is to subclass the NSTextView class and examine each event; another is to set up a delegate object that will be alerted each time the text inside the NSTextView changes. If the change results from a carriage return, our delegate can then grab the last line of the NSTextView object and send that line to Evaluator.

An NSTextView delegate can receive all sorts of special messages when things happen to the NSText object. The one that we care about here is the textDidChange: message, which is sent to the delegate object whenever the text changes. To find out if the text changed because the user hit the Return key, our delegate method asks the window for the current event; it then asks the current event for its characters and checks whether the resulting string is equal to a carriage return.

After the MathPaper user hits the Return key, our delegate method asks the NSTextView object for ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Cocoa and Objective-C: Up and Running

Cocoa and Objective-C: Up and Running

Scott Stevenson
Learning Cocoa with Objective-C, 2nd Edition

Learning Cocoa with Objective-C, 2nd Edition

Apple Computer Inc, James Duncan Davidson
Learning Cocoa

Learning Cocoa

Jonathon Manning, Tim Nugent, Paris Buttfield-Addison

Publisher Resources

ISBN: 0596002351Catalog PageErrata