1: You can’t downcast from Int to CGFloat. You have to initialize a CGFloat with the Int as input.
return CGFloat(screenHeight) / CGFloat(cellCount)
2: Use the min and max functions defined by the standard library. They’re defined as follows:
func min<T : Comparable>(x: T, y: T, rest: T...) -> T
func max<T : Comparable>(x: T, y: T, rest: T...) -> T
Usage is as follows.
let lower = min(17, 42) // 17
let upper = max(17, 42) // 42