MIN() and MAX() in Swift and converting Int to CGFloat
        Posted  
        
            by 
                gotnull
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by gotnull
        
        
        
        Published on 2014-06-13T09:15:34Z
        Indexed on 
            2014/06/13
            9:25 UTC
        
        
        Read the original article
        Hit count: 411
        
I'm getting some errors with the following methods:
1) How do I return screenHeight / cellCount as a CGFLoat for the first method?
2) How do I use the equivalent of ObjC's MIN() and MAX() in the second method?
func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
    var cellCount = Int(self.tableView.numberOfRowsInSection(indexPath.section))
    return screenHeight / cellCount as CGFloat
}
// #pragma mark - UIScrollViewDelegate
func scrollViewDidScroll(scrollView: UIScrollView) {
    let height = CGFloat(scrollView.bounds.size.height)
    let position = CGFloat(MAX(scrollView.contentOffset.y, 0.0))
    let percent = CGFloat(MIN(position / height, 1.0))
    blurredImageView.alpha = percent
}
© Stack Overflow or respective owner