美文网首页Swift 4
Swift4 学习笔记-宏定义

Swift4 学习笔记-宏定义

作者: 村雨灬龑 | 来源:发表于2018-01-02 13:59 被阅读0次

创建一个. swift 文件

//封装的日志输出功能(T表示不指定日志信息参数类型)
func XNSLog<T>(_ message:T, file:String = #file, function:String = #function,
              line:Int = #line) {
    #if DEBUG
        //获取文件名
        let fileName = (file as NSString).lastPathComponent
        //当前时间
        let formatter = DateFormatter()
        //日期样式
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        let nowTime = formatter.string(from: Date())
        //打印日志内容
        print("[\(nowTime) : \(fileName) : \(line)]  \(message)")
    #endif
}

func XParserPlist<T>(_ name:T) -> Any {
    let path = Bundle.main.path(forResource: "BillSourcePlist", ofType: "plist")
    let dic = NSDictionary(contentsOfFile: path!)!
    return dic[name]!
}


// 屏幕的bounds
let kScreen = UIScreen.main.bounds
// 屏幕的宽
let kScreenW = UIScreen.main.bounds.size.width

// 屏幕的高
let kScreenH = UIScreen.main.bounds.size.height

相关文章

网友评论

    本文标题:Swift4 学习笔记-宏定义

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