Reputation: 46387
Same question as: Do __LINE__ __FILE__ equivalents exist in C#?
But for Objective-C in iPad/iPhone SDK Xcode? This would really help my NSLog statement be a lot more readable over time.
Upvotes: 11
Views: 7096
Reputation: 373
So even easier visually. Displays only the file name without a path. It is convenient to observe the terminal without text wrapping.
Writing:
NSLog(@"Log: %s %d", (strrchr(__FILE__, '/') ?: __FILE__ - 1) + 1, __LINE__);
Output is:
Log: file.m 340
Upvotes: 11
Reputation: 2528
Note that you cannot implicitly cast the string constant returned by FILE to a char *.
This throws up a compiler warning. "Deprecated conversion from string constant to 'char *'".
The above should read:
NSLog(@"%s:%d", (char *) __FILE__, __LINE__);
Upvotes: 0
Reputation: 59623
I would have to go back and look at the Objective C documentation, but my guess would be "most certainly" since these are core to the C Programming Language and Objective C is an extension of it.
Upvotes: 1
Reputation: 99092
Yes, they do:
NSLog(@"%s:%d", __FILE__, __LINE__);
Output is e.g.:
/Path/to/file.m:42
Upvotes: 7