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

String formatting


When dealing with different types of objects, especially inserting/appending them into a string, you need to specify their types inside the string, for which we use format specifiers. Printing to the console, for example, requires a string to be printed; it's the only accepted format. Let's see how to insert different objects inside it, to be properly printed to the console:

// Here we print a message, it's already a string.
NSLog(@"I'm a message. A string");

However, if you want to print a value stored in a property or instance variable, you should specify its type inside in order to properly replace it with the value outside:

/*
    Now we print the string value stored on a property
    The console will print the message: "Hello, Mr. Gaius Julius Caesar"
*/
NSString *myStringObject = @"Gaius Julius Caesar";
NSLog(@"Hello, Mr. %@", myStringObject);

Notice %@ inside the message. It specifies that the value is a string. This is how we can specify the object's type, using a percentage...