Can __FILE__ not print the full path?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Can __FILE__ not print the full path?

Alex Hall
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/8C1EFB77-F317-45A0-8E71-C69098A9AF1F%40icloud.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can __FILE__ not print the full path?

Jens Alfke

On Nov 28, 2015, at 6:35 AM, Alex Hall <[hidden email]> 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

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/D074FBAA-3BFA-4DAD-917C-33D3E494BCB8%40mooseyard.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can __FILE__ not print the full path?

Kevin Ballard
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
 
On Sat, Nov 28, 2015, at 12:51 PM, Jens Alfke wrote:
 
On Nov 28, 2015, at 6:35 AM, Alex Hall <[hidden email]> 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
 


--
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 [hidden email].
To post to this group, send email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
 

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/1448835880.3055104.452942625.414AA51C%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.