CGRectDivide is deprecated in swift 3
Asked Answered
E

1

5

As swift 3 says CGRectDivide is deprecated and the replacement is divided(atDistance: CGFloat, from fromEdge: CGRectEdge) -> (slice: CGRect, remainder: CGRect).

As I know CGRectDivide was dividing a source rectangle into two component rectangles by default. The questions is what to do and what to use to perform the same operation what CGRectDivide does using swift 3?

Update 1: The swift 2 function looks like:

fileprivate func isLeftPointContainedWithinBezelRect(_ point: CGPoint) -> Bool{
    if let bezelWidth = SlideMenuOptions.leftBezelWidth {
        var leftBezelRect: CGRect = CGRect.zero
        var tempRect: CGRect = CGRect.zero

        CGRectDivide(view.bounds, &leftBezelRect, &tempRect, bezelWidth, CGRectEdge.minXEdge)

        print("------> slidee1")

        return leftBezelRect.contains(point)
    } else {
        return true
    }
}
Ejector answered 19/9, 2016 at 5:10 Comment(0)
H
13

In swift 3 you can write like this.

let rect = CGRect(x: 0, y: 0, width: 50, height: 50)
let (slice, remainder) = rect.divided(atDistance: 5.0, fromEdge: .minXEdge)
print(slice)
print(remainder)

Output

(0.0, 0.0, 5.0, 50.0)
(5.0, 0.0, 45.0, 50.0)

Edit: In your case it is written as.

(leftBezelRect, tempRect) = view.bounds.divided(atDistance: bezelWidth, fromEdge: .minXEdge)
Hi answered 19/9, 2016 at 5:21 Comment(2)
Well, how do u use slice and remainder to divide the source? I've updated my question with a code snapped.Ejector
Thanks, Nirav, u helped me a lot!Ejector

© 2022 - 2024 — McMap. All rights reserved.