zumzum zumzum - 2 years ago 116
Swift Question

Swift: determine what object called a function?

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.

Any suggestion?

Answer Source

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)"

It's quite simple. Ignore syntax highlight, it's wrong.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download