Swift-CommonFunctions

2017-03-30  本文已影响31人  Supremodeamor

Swift中没有宏定义,那么全局常量可以建立一个空的Swift文件去统一声明。

// 屏幕的物理宽度
let kScreenWidth = UIScreen.mainScreen().bounds.size.width
// 屏幕的物理高度
let kScreenHeight = UIScreen.mainScreen().bounds.size.height
// navigationBar高度
let kNaviBarHeight: CGFloat = 64
// tabbar高度
let kTabBarHeight: CGFloat = 49

复杂的宏在Swift中则使用全局函数代替

func kRGBA (r:CGFloat, g:CGFloat, b:CGFloat, a:CGFloat) -> UIColor {
    return UIColor(red: r/255.0, green: g/255.0, blue: b/255.0, alpha: a)
}
// 沙盒路径
func kAppPath() -> String! {
    return NSHomeDirectory()
}

// Documents路径
func kBundleDocumentPath() -> String! {
    return NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as! String
}

// Caches路径
func kCachesPath() -> String! {
    return NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true).first as! String
}
func printLog<T>(message: T,
             file: String = #file,
             method: String = #function,
             line: Int = #line)
{
    #if DEBUG
        print("\((file as NSString).lastPathComponent)[\(line)], \(method): \(message)")
    #endif
}
上一篇下一篇

猜你喜欢

热点阅读