37
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

swiftでデバッグログ

Last updated at Posted at 2015-02-16

objective-cの時に使用していたdebug時のみログを吐き出すマクロをswiftで使えるようにしてみた。

project設定を編集

Build Setting内のOther Swift Flags
-DDEBUGを設定する。

sample.png

実装

log.swift
func debugLog(_ obj: Any?,
              file: String = #file,
              function: String = #function,
              line: Int = #line) {
    
    let fileName = URL(string: file)?.lastPathComponent ?? "unknown"

    #if DEBUG
        if let o = obj {
            print("[\(fileName):\(function) Line:\(line)] : \(o)")
        } else {
            print("[\(fileName):\(function) Line:\(line)]")
        }
    #endif
}

使い方

let hoge = Hoge()
debugLog(hoge)

37
31
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
37
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?