Update CGRectMake to CGRect in Swift 3 Automatically

yonasstephen picture yonasstephen · Jul 12, 2016 · Viewed 80.3k times · Source

Now that CGRectMake , CGPointMake, CGSizeMake, etc. has been removed in Swift 3.0, is there any way to automatically update all initializations like from CGRectMake(0,0,w,h) to CGRect(x:0,y:0,width:w,height:h). Manual process is.. quite a pain.

Not sure why Apple don't auto convert this when I convert the code to Current Swift Syntax...

Answer

rob mayoff picture rob mayoff · Jul 12, 2016

The simplest solution is probably just to redefine the functions Apple took away. Example:

func CGRectMake(_ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) -> CGRect {
    return CGRect(x: x, y: y, width: width, height: height)
}

Put that in your module and all calls to CGRectMake will work again.