Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dereferencing a pointer when using NSLog in Objective-C

NSDate *now = [NSDate date];
NSLog(@"This NSDate object lives at %p", now);
NSLog(@"The date is %@", now);

Ok, from this code, I know that now is a pointer to an NSDate object, but on the code at line 3, how can you dereference a pointer without an asterisk? Why don't we do code like this on the 3rd line:

NSLog(@"The date is %@", *now);
like image 866
user3090658 Avatar asked Dec 19 '13 04:12

user3090658


1 Answers

The %@ format specifier takes a pointer to an object, so there's no need to dereference the pointer in the parameter list. In general, there's no need to dereference pointers to Objective C objects.

like image 78
godel9 Avatar answered Sep 23 '22 19:09

godel9