In notebook 02, Chris defines this helper function:
// This function prints out the calling function's name. This
// is useful to see what is going on in your program.
func trace(function: String = #function) {
print(function)
}
that takes this #function argument. From the use of trace I gather its value is the name of the function in which we are when calling trace(). I tried to find more about it and if there are others # arguments like this that we can use in swift but didn’t find anything useful. If someone knows more, I’d love to some more information about those!
bradlarson
(Brad Larson (formerly Swift for TensorFlow))
2
Yep, I think that is a complete list. These work the same way as the old C __FILE__ and __LINE__ macros. When used in a default argument position, they get somewhat magic behavior of being evaluated in the caller’s context, so you get its location. This is important for things like assert etc, which want to report file/line/col location information where a crash happens.