Building in quick

Is there a way to contract in swift ?, since there is no preprocessor, this seems difficult.

What I would like to do is something similar to the following code.

// log a variable name and its value
#define LOGV(V) NSLog(@"%s = %@", #V, V);
NSString *myString = @"this";
LOGV(myString);    // prints out ->  "myString = ???"

After looking, dumpit seems that there is no way to reflect the variable name.

let myString = "this"
dump(myString, name:"myString", indent: 0 maxDepth: 0, maxItems: 1)
+4
source share
2 answers

I also wanted to do the same in Swift, so I recently wrote a debug-logging utility that instead builds variables at runtime (reading all the code!)

You may find this interesting. https://github.com/inamiy/DebugLog

0
source

There is no way to do this in Swift. If you ABSOLUTELY want to do this, you can always start the C preprocessor through your Swift source.

-1
source

Source: https://habr.com/ru/post/1543733/


All Articles