Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Sometimes, you want to display a string that has certain attributes for a range of characters. For example, suppose that you want to display the string “Big Nerd Ranch” and want the letters 0 through 2 to be underlined, the letters 0 through 7 to be green, and the letters 9 through 13 to be subscripts.
When dealing with a range of numbers, Cocoa uses the struct NSRange, which has two members—location and length—both of which are integers. The location is the index of the first item, and the length is the number of items in the range. You can use the function NSMakeRange() to create an NSRange.