Date
Dec. 22nd, 2024
 
2024年 11月 22日

Post: iOS : Debug 与 print 001[Swift]

iOS : Debug 与 print 001[Swift]

Published 12:02 Feb 27, 2015.

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

Source format: Markdown

Table of Content

接上文,本篇是 Swift 版本。

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

/*!
*  @method println:
*
*  @discussion custom print function
*
*/
class func println<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"
println("abc = \(abc)")
println("Some log")

看看输出结果:

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

* ----------------------
* File: ViewController.swift
* Line: 20
* Function: viewDidLoad()
* Some log
Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
开发、设计与写作皆为所长。
热爱苹果、钟情色彩。
随时恭候 垂询