Can __FILE__ not print the full path?

17 views
Skip to first unread message

Alex Hall

unread,
Nov 28, 2015, 9:35:45 AM11/28/15
to swift-l...@googlegroups.com
Hello list,
I recently discovered __LINE__, __FUNCTION__, and the rest, and they're brilliant for debugging. My only complaint is that __FILE__ prints the full path, which is quite long as my files are all in iCloud Drive. Is there some way to have that keyword print only the actual filename? No two files in my project are the same name, so I don't need the full path. I could strip everything else away in a function, but I wanted to know if there's a built-in way of doing that first. Thanks.

Jens Alfke

unread,
Nov 28, 2015, 3:51:56 PM11/28/15
to Alex Hall, swift-l...@googlegroups.com
On Nov 28, 2015, at 6:35 AM, Alex Hall <meh...@icloud.com> wrote:

I recently discovered __LINE__, __FUNCTION__, and the rest, and they're brilliant for debugging.

Yup! I use __func__, which IIRC prints the name in a nicer way than __FUNC__.

My only complaint is that __FILE__ prints the full path, which is quite long as my files are all in iCloud Drive.

How about: #define SHORT_FILE  [@ __FILE__ lastPathComponent]

—Jens

Kevin Ballard

unread,
Nov 29, 2015, 5:24:45 PM11/29/15
to swift-l...@googlegroups.com
Your reply looks like it's meant for Obj-C.
 
In Swift, AFAIK the only keywords of this type are __FILE__, __LINE__, __COLUMN__, and __FUNCTION__.
 
If you want to use __FUNCTION__ without the path, you're going to need to write a function to do it, or just say something like
 
    (__FILE__ as NSString).lastPathComponent
 
-Kevin Ballard
--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swift-languag...@googlegroups.com.
To post to this group, send email to swift-l...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
 
Reply all
Reply to author
Forward
0 new messages