Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the name of the current file in Swift?

Tags:

swift

I need to get the current filename in Swift programatically.

Is it possible? Is there any hack that can be used to do the same?

like image 331
Ankit Goel Avatar asked Sep 21 '25 10:09

Ankit Goel


1 Answers

Yes, you can simply use #file macro to get the name of the current file. You can

Eg. just try compiling the following file Swift 3:

println(#file)

Swift 2 or older:

println(__FILE__)
like image 145
Ankit Goel Avatar answered Sep 23 '25 03:09

Ankit Goel