Swift优雅的打印

147 阅读1分钟

代码复制即可

//  ChLog.swift
//  IntelligentGas
//
//  Created by jszx-ch on 2021/4/21.
//  Copyright © 2021 ch. All rights reserved.
//

import Foundation

/// 能够快速定位打印的具体位置
func printLog<T>(_ msg: T,
            file: NSString = #file,
            line: Int = #line,
            fn: String = #function) {
    #if DEBUG
    let prefix = "\(file.lastPathComponent)_\(line)_\(fn):"
    print(prefix, msg)
    #endif
}

打印结果:

image.png