WordCounter

Figure 22.6 shows a program that counts the number of words in a text field as well as the number of unique words. Text fields are updated with the values.

Figure 22.6  WordCounter screenshot

WordCounter screenshot

The code for this application is straightforward. In Xcode, make a new Cocoa Application (not document-based) called WordCounter. Add the objects seen in Figure 22.6: an NSTextView, a count button, a progress indicator, and two labels for the different counts. Configure your object layout appropriately. Update your AppDelegate class to point to the UI items, as well as the -count: action method:

#​i​m​p​o​r​t​ ​<​C​o​c​o​a​/​C​o​c​o​a​.​h​>​ @​i​n​t​e​r​f​a​c​e​ ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

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