Skip to content

Instantly share code, notes, and snippets.

@therealbnut
Created January 26, 2016 04:15
Show Gist options
  • Save therealbnut/e6f46a673b4f09c9cdf7 to your computer and use it in GitHub Desktop.
Save therealbnut/e6f46a673b4f09c9cdf7 to your computer and use it in GitHub Desktop.
public struct SourceLocation: CustomDebugStringConvertible {
init(file: String = __FILE__, line: Int = __LINE__, column: Int = __COLUMN__, function: String = __FUNCTION__) {
self.file = file
self.line = line
self.column = column
self.function = function
}
public let file: String
public let line: Int
public let column: Int
public let function: String
public var debugDescription: String {
return "\(function) @ \(file):\(line):\(column)"
}
}
@therealbnut
Copy link
Author

Can be used to get the current location in source, as a structure.
For example:

let location = SourceLocation()
print("\(location)")
print("current file: \(location.file)")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment