swift 沒有C++的 redefine function 功能
所以只能下面方式來暫用
另一種方式使用 swift 內建的 debugPrint()
Swift: Extending functionality of print() function
STRIPPING PRINT AND DEBUGPRINT IN SWIFT FOR RELEASE BUILDS
Swift print, println, NSLog
public func debugPrint(_ items: Any..., separator: String = " ", terminator: String = "\n")
import Foundation public func DPrint(_ items: Any..., separator: String = " ", terminator: String = "\n") { #if DEBUG // for Debug Mode let output = items.map { "\($0)" }.joined(separator: separator) Swift.print(output, terminator: terminator) #else // for Relase Mode // ... #endif } public func RPrint(_ items: Any..., separator: String = " ", terminator: String = "\n") { #if DEBUG // for Debug Mode #else // for Relase Mode let output = items.map { "\($0)" }.joined(separator: separator) Swift.print(output, terminator: terminator) #endif }
import Foundation class MyViewController: UIViewController { func MyFun() { print("FUNC: \(#file),\(#function)") debugPrint("FUNC: \(#file),\(#function)") DPrint("FUNC: \(#file),\(#function)") RPrint("FUNC: \(#file),\(#function)") } }
沒有留言:
張貼留言