【发布时间】:2019-05-02 13:35:08
【问题描述】:
我在UIlabel 中添加文本,以及它的性能成本(我使用了构建时间分析器using this link)。如何优化这段代码?
for value in model?.offerings ?? [] {
offeringsLabel.text = offeringsLabel.text! + " | " + (value.name ?? "") + "," + (value.type ?? "")//this addition cost to performance
}
我也试过[ array].joined,但这并没有什么不同
【问题讨论】:
-
大部分是
??——它在构建期间的类型推断检查存在一些问题。如需参考,请查看here。 -
@user28434 你是对的。但是模型?.offerings 来自网络服务。 &它的可选。所以在 codable 中定义的任何解决方法?我正在使用 -
struct Response:Codable { var offerings:[offerings]? -
字符串连接行中还有 2 个
??。你只需要帮助类型推断,通过将带有??的sn-ps 提取到变量中,explicitly提供你期望的类型。 -
使用警卫,这样你就没有所有这些选项。然后它会表现得更好。
标签: ios arrays swift optimization compilation-time