有没有办法在 Swift 语言中获取行号和函数名? [英] Is there a way to get line number and function name in Swift language?
本文介绍了有没有办法在 Swift 语言中获取行号和函数名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Objective-C 中,我们可以使用 __LINE__
和 __PRETTY_FUNCTION__
宏.这些在 Swift 语言中没有公开.有没有其他方法可以在 Swift 中获取类似信息?
In Objective-C, we could use the __LINE__
and __PRETTY_FUNCTION__
macros. These are not exposed in the Swift language. Is there another way to get similar information in Swift?
推荐答案
Swift 语言参考定义 一些提供这种行为的特殊文字":
The Swift Language Reference defines a few "special literals" that offer this behavior:
Literal Type Value
#file String The name of the file in which it appears.
#line Int The line number on which it appears.
#column Int The column number in which it begins.
#function String The name of the declaration in which it appears.
这篇关于有没有办法在 Swift 语言中获取行号和函数名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文