Book Image

Objective C Memory Management Essentials

Book Image

Objective C Memory Management Essentials

Overview of this book

Table of Contents (18 chapters)
Objective-C Memory Management Essentials
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Object mutability


Cocoa and Cocoa Touch also provide some mutable versions of its immutable classes. Once a mutable object is created, its contents can be partially or completely removed or modified. As we saw immutable array objects—an instance of NSArray—in the previous topic, I will now show you its mutable version, the NSMutableArray class, from which we will create our objects as an instance, as you can see in the following code:

/*
  =============================================
  We will create now a mutable version of an array, using the class NSMutableArray.
  =============================================
*/
NSMutableArray *mutableSampleArray = [[NSMutableArray alloc] init];

/*
  =============================================
  Now, we assign to it the list of strings:
  "String 1", "String 2", "String 3"
  =============================================
*/
mutableSampleArray = @[@"String 1",
       @"String 2",
        @"String 3"];

/*
  =========================================...