MIN() and MAX() in Swift and converting Int to CGFloat

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)