有没有办法在swift中做字符串化呢?因为没有预处理器,所以看起来有点困难。
我想要做的是类似于下面的代码。
// log a variable name and its value
#define LOGV(V) NSLog(@"%s = %@", #V, V);
NSString *myString = @"this";
LOGV(myString); // prints out -> "myString = ???"看过dump之后,似乎没有办法反映变量名。
let myString = "this"
dump(myString, name:"myString", indent: 0 maxDepth: 0, maxItems: 1)发布于 2014-06-25 18:05:57
我也想在Swift中做同样的事情,所以我最近写了debug-logging,它在运行时将变量串化(读取整个代码!)
您可能会发现这很有趣。https://github.com/inamiy/DebugLog
发布于 2014-06-09 15:54:24
在Swift中无法做到这一点。如果你真的想这样做,总是可以在你的Swift源代码上运行C预处理器。
https://stackoverflow.com/questions/24105105
复制相似问题