//在obj-c的NSLog中可以用c++的__PRETTY_FUNCTION__
NSLog(@"%s", __PRETTY_FUNCTION__);
//show
-[YourCurrentClassName yourCurrentFunctionName:]
//在swift中還不行用,stackOverFlow上有人提出這個方式來解決
func pretty_function(file:String = __FILE__, function:String = __FUNCTION__, line:Int = __LINE__) {print("file:\(file.lastPathComponent) function:\(function) line:\(line)")}
P.S. 現在swift的String已經把lastPathComponent拿掉,所以要改為下面的方式
func pretty_function(file:String = __FILE__, function:String = __FUNCTION__, line:Int = __LINE__) {print("file:\((file as NSString).lastPathComponent) function:\(function) line:\(line)")}
沒有留言:
張貼留言