1

I am converting an Objective C code to Swift. Found out this code :

#define MPLog(fmt, ...) \
    do { \
        if ([MPPush getLoggingPref] && ![MPPush getEnvironmentPref]) { \
            NSLog(fmt, ##__VA_ARGS__); \
        } \
    } while(0)  

I am aware what this code does but I am not able to convert this. I found this great link but this has only Objective C reference.

Nitish
  • 13,845
  • 28
  • 135
  • 263

1 Answers1

1

Swift provides some expressions in order to log, among others line number and method name:

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.

For example:

func logFunctionName(string: String = #function) {
    print(string)
}
func myFunction() {
    logFunctionName() // Prints "myFunction()".
}

For more information, check the official documentation

Cris
  • 774
  • 9
  • 32