I'm a little bit confused about the syntax of NSLog. For example,
NSString *nameString = @"Name"; NSLog(@"nameString is: %@", nameString);If my understanding is correct (which it very well may not be), then nameString is defined to be a pointer to a String. I thought then that this would print the memory address that nameString holds, not the value of that address. So, if that is true, then in the NSLog statement, to get the value of the pointer, shouldn't we need to use the asterisk notation to access what nameString points to like this:
NSLog(@"nameString is: %@", *nameString);? It has been a little while since programming in C, but since Objective-C is a superset of C I thought they would behave similarly.
An explanation would be greatly appreciated! Thanks!
The command %@ is like "shortcut" that calls the method -description
on the receiver. For an NSString it simply display the string itself, since is inherited from NSObject you can override it, very usefull if you create for own class. In that case the default behaviur is print the value of the pointer.
If you want to print the address of the pointer in the string just replace with :
NSLog(@"nameString is: %p", nameString)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With