I was experimenting with methods of debug logging in Swift and came across an interesting find. If you use the __FILE__
, __FUNCTION__
, __LINE__
and __COLUMN__
“macros” as default function parameter values in Swift the value is set to the file, function etc of the caller rather than the details of the called functions location.
This means you can automatically pass information about a calling function by providing default values. For example:
1 2 3 4 5 6 7 |
|
This will display a message of the form:
1
|
|
Clearly __FILE__
, __FUNCTION__
, __LINE__
and __COLUMN__
are not implemented using a preprocessor but then we knew that already.