【发布时间】:2016-10-17 04:50:06
【问题描述】:
我最近开始使用构建时间分析器分析我的 Swift 项目的编译时间:https://github.com/RobertGummesson/BuildTimeAnalyzer-for-Xcode。我注意到这个方法编译起来特别慢:
func placeStatusSwitch() {
let switchX = tableView.center.x - (statusSwitch.frame.width / 2)
var switchY = tableView.contentInset.top - statusSwitch.frame.height + tableView.contentOffset.y
if let refreshControl = refreshControl {
let navigationBarHeight = navigationController?.navigationBar.frame.height ?? 0
let expectedTopInset = UIApplication.shared.statusBarFrame.height + navigationBarHeight + statusSwitch.frame.height + MyTheme.verticalMargin - 4
if tableView.contentInset.top >= expectedTopInset || refreshControl.isRefreshing {
switchY = switchY - refreshControl.frame.height
}
}
statusSwitch.frame = CGRect(x: switchX, y: switchY, width: statusSwitch.frame.width, height: statusSwitch.frame.height)
}
我尝试使用以下方式更改 Nil Coalescing Operator:
var navigationBarHeight: CGFloat = 0
if let navBarHeight = navigationController?.navigationBar.frame.height {
navigationBarHeight = navBarHeight
}
但是编译时间仍然很慢。有什么想法可能导致减速吗?
【问题讨论】:
-
对于较慢的执行,您必须熟悉 gcd.. 在此运行您希望在后台减慢的进程。并在执行期间使用当前进程对其进行管理。都是关于线程管理的。
-
Scientific Wild-Ass Guess (SWAG):会不会是在算术表达式的类型推断期间?如果你给出这些明确的类型会有帮助吗?
-
@ColinBarrett 你的意思是
switchX等添加CGFloat? -
@KexAri 是的。或者,如果这不起作用,请添加中间绑定。完全猜测,就像我说的那样。