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...