编译速度监测工具BuildTimeAnalyzer
随着swift项目业务代码不断增加,导致项目编译时间越来越长,通过网上查找阅读了几篇关于如何使编译速度提升的文章,现总结如下:
1.使用Optional进行拆包时,不可有多重拆包,例如:
let model = listModel.first
let params = ["test":model?.landName ?? "","hello":model?.statusName ?? "","id":model?.landId ?? "","transform":model?.oneCropId ?? ""]
其编译时间会增加很多,下面分别是写法一、写法二、写法三的编译时间对比,
⚠️不推荐写法一

推荐写法二

2.使用??(nil-coalescing 空合并运算符) 及 ”+“拼接在一起的耗时,例如:
return CGSize(width: 10 + (view?.bounds.width ?? 0), height: (view?.bounds.height ?? 0) + 22)
⚠️不推荐写法一

推荐写法二

3.使用+或+=操作字符串拼接或数组拼接时耗时,例如:
let arr1 = [1,2,3]
let arr2 = [3,4,5]
result = arr1 + arr2 + [10]
⚠️不推荐写法一

推荐写法二

4.使用三元运算符与其他操作符结合或者高阶函数同时使用时耗时,例如:

5.一行代码使用过多的CGFloat转换同时再加上运算符使用时耗时,例如:

6.另外有文章说使用lazy时耗时
参考文章如下:
网友评论