Dustin Johnson
Dustin Johnson

Reputation: 405

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

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!

Upvotes: 34

Views: 23093

Answers (4)

Denis Kutlubaev
Denis Kutlubaev

Reputation: 16154

This kind of issues with pods can also be solved by setting SWIFT_VERSION for a particular pod.

post_install do |installer|
  installer.pods_project.targets.each do |target|

    if ['MessageKit'].include? target.name
      target.build_configurations.each do |config|
        config.build_settings['SWIFT_VERSION'] = '5.0'
      end
    end

  end
end

Upvotes: -2

Karthick C
Karthick C

Reputation: 1529

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

Upvotes: 2

Prashant Gaikwad
Prashant Gaikwad

Reputation: 3810

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)

Upvotes: 25

Leo Dabus
Leo Dabus

Reputation: 236420

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)

Upvotes: 69

Related Questions