0

In many languages I'm able to do something like this

printf("line number %d in file %s\n", __LINE__, __FILE__);

How can I get these debug identifiers in swift? I'd like to see a full list of available debug identifiers.

hfossli
  • 22,616
  • 10
  • 116
  • 130
  • Well, that post is just asking for a single debug identifier @Wain – hfossli Feb 04 '16 at 09:30
  • 1
    It is not a duplicate. Swift isn't just for objective-c. Having `NSLog` in the the title as entry for others searching for answers will be confusing. Swift is for linux, windows, mac, ios and any platform you'd like. This is a much more general question and the question you are referring to is only asking for a single debug identifier. – hfossli Feb 04 '16 at 09:51

1 Answers1

1

With Swift 2.1 and below you are able to get these debug identifiers by

__FILE__
__LINE__
__COLUMN__
__FUNCTION__
__DSO_HANDLE__ 

Can be used like so

print("Function: \(__FUNCTION__), line: \(__LINE__)") 

As of Swift 2.2 they may already be deprecated (time will tell) and replaced with

#namespace
#file
#line
#column
#function
#dsohandle

Can be used like so

print("Function: \(#function), line: \(#line)") 

Sources:
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160201/008982.html https://github.com/apple/swift-evolution/blob/master/proposals/0028-modernizing-debug-identifiers.md
https://bugs.swift.org/browse/SR-669

hfossli
  • 22,616
  • 10
  • 116
  • 130