user1764781 user1764781 - 2 months ago 20
Swift Question

CGRectDivide is deprecated in swift 3

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
}
}

Answer

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)
Comments