I can't find where I read it, but I remember coming across something that suggested it is better to access height of CGRect
s using CGRectGetHeight(rect)
instead of accessing the variable via rect.size.height
CGFloat height = CGRectGetHeight(self.frame);
// vs
CGFloat height = self.frame.size.height;
Most of the time, this has to do with views in my use, and I was wondering if there is a real difference (apart from syntax) that separates these two lines of code.
If one is preferential over the other, an explanation of why would be great!
CGRect structures might store height and width in negative values and CGRectGetHeight
will always return the positive one. In Swift 3.0 CGRect.height
property should be used instead of CGRectGetHeight
.
CGRect.height
Regardless of whether the height is stored in the CGRect data structure as a positive or negative number, this function returns the height as if the rectangle were standardized. That is, the result is never a negative number.
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