16 NSString

NSString is another class like NSDate. Instances of NSString hold character strings. Objective-C developers use NSString instances to hold and manipulate text in their programs.

Creating instances of NSString

In code, you can create an instance of NSString like this:

 ​ ​ ​ ​N​S​S​t​r​i​n​g​ ​*​l​a​m​e​n​t​ ​=​ ​@​"​W​h​y​ ​m​e​!​?​"​;​

Notice that there is no explicit message sent to the NSString class to create the instance. The @"..." is Objective-C shorthand for creating an NSString object with the given character string. This shorthand is known as literal syntax. When you use it, we say that you are creating a literal instance of NSString, or more commonly, an NSString literal.

Instances of NSString ...

Get Objective-C Programming: The Big Nerd Ranch 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.