UIEdgeInsetsInsetRect' has been replaced by instance method 'CGRect.inset(by:)

20,897

Solution 1

The error it is pretty self explanatory. You can use it like this:

var animationRect = frame.inset(by: UIEdgeInsets(top: padding, left: padding, bottom: padding, right: padding))

or simply

var animationRect = frame.insetBy(dx: padding, dy: padding)

Solution 2

Swift 4.2 and Xcode 10

Earlier it was like this -

let bounds = UIEdgeInsetsEqualToEdgeInsets(view.bounds,view.safeAreaInsets)

Now for swift 4.2 -

let bounds = view.bounds.inset(by: view.safeAreaInsets)

Solution 3

UIEdgeInsets in Swift 4.2

Earlier version

let padding = UIEdgeInsets(top: 0, left: 40, bottom: 0, right: 5)
 override func textRect(forBounds bounds: CGRect) -> CGRect {
            return UIEdgeInsetsInsetRect(bounds, padding)
        }
to swift 4.2 and Xcode 10
let padding = UIEdgeInsets(top: 0, left: 40, bottom: 0, right: 5)
 override func textRect(forBounds bounds: CGRect) -> CGRect {
        return rect.inset(by: GlobalClass.language == "ar" ? paddingR : padding)
    }
Share:
20,897
Dustin Johnson
Author by

Dustin Johnson

Updated on June 27, 2020

Comments

  • Dustin Johnson
    Dustin Johnson about 4 years

    I made the mistake up updating my project to Swift 4.2 without waiting for pods to be updated. I have slowly updated all of my code, but there's one line that I can't seem to figure out.

    var animationRect = UIEdgeInsetsInsetRect(frame, UIEdgeInsets(top: padding, left: padding, bottom: padding, right: padding))
    

    The error I receive is,

    UIEdgeInsetsInsetRect' has been replaced by instance method 'CGRect.inset(by:)

    Any help with this would be greatly appreciated!