Both seem to work the same in Swift. Which should we use?
CGRectZero
vs CGRect.zeroRect
GRectMake(1, 1, 1, 1)
vs CGRect(x: 1, y: 1, width: 1, height: 1)
UIEdgeInsetsMake(1, 1, 1, 1)
vs UIEdgeInsets(top: 1, left: 1, bottom: 1, right: 1)
In Swift 3, CGRectZero
is no longer available. CGRect.zero
is your only choice. Learn it, know it, live it.
CGRect.zeroRect
was renamed to CGRect.zero
in iOS 9.0. That is close enough to CGRectZero
(and the same number of keystrokes, counting shift as a keystroke) that I'd recommend CGRect.zero
to anyone who's not an Objective-C coder in the habit of using CGRectZero
.
There's no particular reason to favor one or the other. You should use whichever style you or your team prefers.
Personally, I'd use CGRectZero
because it's shorter and I'm used to it from Objective-C.
I'd go with CGRectMake
for the same reason.
I'd probably use UIEdgeInsets(top:left:bottom:right:)
because I rarely see instances of UIEdgeInsets
, so I'm less likely to remember the order of the arguments in UIEdgeInsetsMake
. (You get placeholders for it when you're typing in a call to UIEdgeInsetsMake
, but when you're reading existing code there's no hints about the argument order.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With