I have a question about the use of the NSLog function in Objective-C while developing for iOS. I am used to C++ syntax so this is a bit new.
In the first case we see that the value of the pointer is passed in the function:
In the second case we see that the pointer itself is passed in the function:
Does this mean that the %@ parameter takes a pointer to the object, and all other (%i, %c, %d, %f, u) take a value. I guess it has something to do with primitive datatypes versus an object?
Does this mean that the %@ parameter takes a pointer to the object
Yes, it takes a pointer to an Objective-C object, which can be of type NSString
or any other NSObject
derived type; in the latter case, the description
method is used to convert the object to a string. You can think of it as the equivalent to %s
for Objective-C strings.
This is how the %@
placeholder is described in Apple does:
Objective-C object, printed as the string returned by descriptionWithLocale: if available, or description otherwise. Also works with CFTypeRef objects, returning the result of the CFCopyDescription function.
Have a look at this Apple document for more details and also "String Format Specifiers".