Swift:确定哪个对象调用了函数? [英] Swift: determine what object called a function?
本文介绍了Swift:确定哪个对象调用了函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一些 Swift 代码,我想知道调用该函数的对象的类.我不想传入任何参数.从函数内部,我想知道是谁调用了它.
I am writing some Swift code and I would like to know the class of the object that called the function. I don't want to pass in any parameters. From within the function I want to be able to know who called it.
有什么建议吗?
推荐答案
如果您想使用 Swift 做到这一点,您可以这样做:
If you want to do that using Swift, you can do this:
func debug(file: String = #file, line: Int = #line, function: String = #function) -> String {
return "\(file):\(line) : \(function)"
}
这篇关于Swift:确定哪个对象调用了函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文