# Swift : CGRect strangeness

**URL:** <https://ifnotnil.com/t/swift-cgrect-strangeness/3387>\
**Category:** Swift\
**Tags:** swift\
**Created:** [12 July 2023 17:08 UTC](https://ifnotnil.com/t/swift-cgrect-strangeness/3387 "2023-07-12T17:08:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveS](https://ifnotnil.com/user_avatar/ifnotnil.com/daves/32/79_2.png) [@DaveS](https://ifnotnil.com/u/DaveS)\
**Post date:** [12 July 2023 17:08 UTC](https://ifnotnil.com/t/swift-cgrect-strangeness/3387/1 "2023-07-12T17:08:54Z")

</div>

Can someone explain how this is even possible?

```auto
 print(" \(r.height) \(r)")

```

one example of results

```auto
39.927 (44.158, 102.511, 284.19, -39.9274)

```

notice, the first 39 is positive, yet the second is negative, BOTH from the same CGRect!

---

<div class="post-metadata">

**Author:** ![BillG](https://ifnotnil.com/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@BillG](https://ifnotnil.com/u/BillG)\
**Post date:** [12 July 2023 21:11 UTC](https://ifnotnil.com/t/swift-cgrect-strangeness/3387/2 "2023-07-12T21:11:35Z")

</div>

I assume “.height” calls [CGRectGetHeight](https://developer.apple.com/documentation/coregraphics/1455645-cgrectgetheight)?

> Regardless of whether the height is stored in the [`CGRect`](https://developer.apple.com/documentation/corefoundation/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.

---

<div class="post-metadata">

**Author:** ![DaveS](https://ifnotnil.com/user_avatar/ifnotnil.com/daves/32/79_2.png) [@DaveS](https://ifnotnil.com/u/DaveS)\
**Post date:** [12 July 2023 23:01 UTC](https://ifnotnil.com/t/swift-cgrect-strangeness/3387/3 "2023-07-12T23:01:25Z")

</div>

no idea… but I would “assume” the both values should be the same… as there is no way to tell if the CGRect is a negative value… without comparing r.origin.y and r.minY
