I'm using these Compilation Swift Flag to identify codes that slow down the compilation time:
-Xfrontend -warn-long-function-bodies=100
-Xfrontend -warn-long-expression-type-checking=100
Then after building, I get warnings
like these:
Instance method 'startFadePositionTitle()' took 2702ms to type-check (limit: 500ms)
for this part of the code:
func startFadePositionTitle() -> CGFloat {
let value: CGFloat = ((backgroundImage.frame.height/2 - contentTitle.frame.height/2) - navbarView.frame.height)/2
return value
}
Can someone explains me what is wrong in this method and what could I possibly improve?
You should break it to smaller chunks, then Swift can do type check more easily. Also the more you tell, the less Swift has to think. So you can help compiler and tell it anything you already know:
func beginFadePositionTitle() -> CGFloat {
let n: CGFloat = 2
let a: CGFloat = self.backgroundImage.frame.height/n
let b: CGFloat = self.contentTitle.frame.height/n
let ab: CGFloat = a - b
let c: CGFloat = self.navbarView.frame.height
let abc: CGFloat = ab - c
return abc/n
}
Instance method 'beginFadePositionTitle()' took 1ms to type-check (limit: 1ms)
This is the result when you tell everything to compiler. See the difference?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With