The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

Build fail with Swift Compiler Error:

The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

on line 9 in code section below (line 150 in BBPMainController.swift).

I have tried to comment out sections and line 150 together with expressions where aboveAlpha is used and it does the trick.

Have been unable to understand why and would appreciate brighter eyes to help out.



Code Block
func scrollViewDidScroll(_ scrollView: UIScrollView) {
// -- Update overlayer alpha value --
let maxAlphaValue: CGFloat = 0.75
// Calcuate alpha
let aboveAlpha = 0 - (maxAlphaValue - maxAlphaValue * ((scrollView.contentOffset.y - view.bounds.height) / view.bounds.height)) + maxAlphaValue * 2
let belowAlpha = maxAlphaValue - maxAlphaValue * ((scrollView.contentOffset.y - view.bounds.height) / view.bounds.height) + maxAlphaValue
// Set alpha or 0 if alpha is greater than 1
applocationScrollOverlayerAboveView.alpha = aboveAlpha > 1 ? 0 : max(0, min(1, aboveAlpha))
applocationScrollOverlayerBelowView.alpha = belowAlpha > 1 ? 0 : max(0, min(1, belowAlpha))
// -- Update transform scale and view alpha value --
let minScaleValue: CGFloat = 0.6
let scale: CGFloat
if aboveAlpha > 1 {
scale = ((scrollView.contentOffset.y - view.bounds.height * 2) / view.bounds.height) * minScaleValue + abs(minScaleValue - 1)
} else {
scale = 0 - ((scrollView.contentOffset.y - view.bounds.height) / view.bounds.height) * minScaleValue + abs(minScaleValue - 1)
}
applicationController.view.transform = CGAffineTransform(scaleX: scale, y: scale)
applicationController.view.alpha = max(0, min(1, scale))
}




Replies

One thing to try is to declare an explicit type for aboveAlpha -- it looks like it should be a CGFloat?
If that's not sufficient, then follow through with the compiler's instruction of making individual variables for the math sub expressions, and then declare aboveAlpha to just be the last set of math expressions to make the value.