user1764781 user1764781 - 1 year ago 221
Swift Question

CGRectDivide is deprecated in swift 3

As swift 3 says

is deprecated and the replacement is
divided(atDistance: CGFloat, from fromEdge: CGRectEdge) -> (slice: CGRect, remainder: CGRect)

As I know
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 =
var tempRect: CGRect =

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

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

return leftBezelRect.contains(point)
} else {
return true

Answer Source

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)


(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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download