美文网首页
2019-07-13 Swift 之DebugLog or De

2019-07-13 Swift 之DebugLog or De

作者: LV大树 | 来源:发表于2019-07-13 15:01 被阅读0次

对于OC 我们很常用的吧,对NSLog 进行重写。

下面有请Swift 版本的

首先需要定义一下DEBUG

image.png

class DebugLogTools: NSObject {
    static func debugLog(_ item: Any){
        #if DEBUG
            print(item)
        #else
        #endif
    }
}


extension NSObject{
    func dPrint(@autoclosure _ item: Any) -> () {
        
        #if DEBUG
        print(item)
        #else
        #endif
    }
}

用法如下:


class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        debugPrint("debugPrint-->> flsflsdjlfldsjf")
        
        
        DebugLogTools.debugLog("debugLog--->>flsflsdlflsdflslfjsldjfjoweowuroweur")
        
        dPrint("flsflsdjlfjdslfjlsdfldslfsdlfjlsdjl")
        
    }


}


你会喜欢哪一种呢。

相关文章

网友评论

      本文标题:2019-07-13 Swift 之DebugLog or De

      本文链接:https://www.haomeiwen.com/subject/bgxmkctx.html