Update CGRectMake to CGRect in Swift 3 Automatically

后端 未结 3 421
迷失自我
迷失自我 2020-12-14 13:55

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,

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-14 14:36

    Short answer: don't do it. Don't let Apple boss you around. I hate CGRect(x:y:width:height:). I've filed a bug on it. I think the initializer should be CGRect(_:_:_:_:), just like CGRectMake. I've defined an extension on CGRect that supplies it, and plop that extension into every single project the instant I start.

    extension CGRect {
        init(_ x:CGFloat, _ y:CGFloat, _ w:CGFloat, _ h:CGFloat) {
            self.init(x:x, y:y, width:w, height:h)
        }
    }
    

    That way, all I have to do is change "CGRectMake" to "CGRect" everywhere, and I'm done.

提交回复
热议问题