O'Reilly logo

Programming in Objective-C, Sixth Edition by Stephen G. Kochan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mutable Versus Immutable Objects

When you create a string object by writing an expression such as

@"Programming is fun"

you create an object whose contents cannot be changed. This is referred to as an immutable object. The NSString class deals with immutable strings. You will often want to deal with strings whose characters you can change. For example, you might want to delete some characters from a string or perform a search-and-replace operation on a string. You handle these types of strings through the NSMutableString class.

Program 15.4 shows basic ways to work with immutable character strings in your programs.

Program 15.4

// Basic String Operations#import <Foundation/Foundation.h>int main (int argc, char * ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required