美文网首页
SWIFT 的一些小知识点

SWIFT 的一些小知识点

作者: liangdahong | 来源:发表于2016-10-12 15:36 被阅读31次

1、NSLog

在 oc 中使用NSLog,在 swift 中为 print

1.1、自定义 Log 函数

func IHLog<T>(message: T ,
            file: String = (#file as NSString).lastPathComponent,
            funcName: String = #function, linNUm: Int = #line) -> () {
        print("\(file) [\(funcName)] \(linNUm) : \(message)")
}

1.2、Log 函数的一点优化

在 oc 中使用 DEBUG 控制 log的输出,怎么实现就不说了
swift

第1步.png
第2步.png
第3步.png
func IHLog<T>(message: T ,
            file: String = (#file as NSString).lastPathComponent,
            funcName: String = #function, linNUm: Int = #line) -> () {
    #if IS_DEBUG
        print("\(file) [\(funcName)] \(linNUm) : \(message)")
    #endif
}

PS: IS_DEBUG 是你随便取的哦 在添加的地方必须为: -D+名称,这里我取为 IS_DEBUG

大功告成,release 环境下不会有 log 信息了、O(∩_∩)O哈哈~

Github源码
我的博客

相关文章

网友评论

      本文标题:SWIFT 的一些小知识点

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