Date
Jul. 21st, 2024
 
2024年 6月 16日

Post: iOS : Debug 与 print 002[Swift]

iOS : Debug 与 print 002[Swift]

Published 12:02 Feb 27, 2015.

Created by @ezra. Categorized in #Programming, and tagged as #iOS.

Source format: Markdown

Table of Content

接上文,本篇我们借鉴一下 JavaScript 中的 console.log:

//
//  Console.swift
//  Console
//
//  Created by Meniny on 15/7/27.
//  Copyright © 2015年 Meniny. All rights reserved.
//
import Foundation

class console {

    /*!
    *  @method log:
    *
    *  @discussion JavaScript like print method
    *
    */
    class func log<T>(message: T, file: String = __FILE__, method: String = __FUNCTION__, line: Int = __LINE__) {
        #if DEBUG
            print("* ----------------------\n* File: \((file as NSString).lastPathComponent)\n* Line: \(line)\n* Function: \(method)\n* \(message)\n")
        #else
            // save logs
        #endif
    }
}

与上一篇类似,我们的输出依然会额外添加文件名、方法名、行号等信息。

let abc = "def"
console.log("abc = \(abc)")
console.log("Some log")

看看输出结果:

* ----------------------
* File: ViewController.swift
* Line: 19
* Function: viewDidLoad()
* abc = def

* ----------------------
* File: ViewController.swift
* Line: 20
* Function: viewDidLoad()
* Some log
Pinned Message
HOTODOGO
I'm looking for a SOFTWARE PROJECT DIRECTOR / SOFTWARE R&D DIRECTOR position in a fresh and dynamic company. I would like to gain the right experience and extend my skills while working in great teams and big projects.
Feel free to contact me.
For more information, please view online résumé or download PDF
本人正在寻求任职 软件项目经理 / 软件技术经理 岗位的机会, 希望加⼊某个新鲜⽽充满活⼒的公司。
如有意向请随时 与我联系
更多信息请 查阅在线简历下载 PDF