swift优化方法总结

2018-10-12  本文已影响11人  小橘子成长记

🏷️

计算消耗时间

1.计算方法


func measure(f:()->()){

    let start = CACurrentMediaTime()

    f()

    let end = CACurrentMediaTime()

    print("测量时间:\(end - start)")

}

2.调用计算方法,打印消耗时间

measure {
            dPrint {"只有debug模式才打印"}
        }
image.png

只在debug模式下,打印log

1.封装打印方法

func dPrint(item:() -> Any){
    #if DEBUG
    print(item())
    #endif
}

2.使用dPrint方法代替print方法

dPrint {"只在debug模式下打印log"}

这样打包的项目就不会走这些打印方法。

上一篇 下一篇

猜你喜欢

热点阅读