Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C xcode: Equivalent of __FILE__ and __LINE__ from C/C++?

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.

like image 256
MikeN Avatar asked May 03 '10 18:05

MikeN


1 Answers

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
like image 190
iSavaDevRU Avatar answered Oct 20 '22 23:10

iSavaDevRU