34

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!

Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
Dustin Johnson
  • 405
  • 1
  • 4
  • 5

4 Answers4

68

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)
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
24

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)
Prashant Gaikwad
  • 3,493
  • 1
  • 24
  • 26
2

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)
    }
Karthick C
  • 1,519
  • 17
  • 16
-2

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
Denis Kutlubaev
  • 15,320
  • 6
  • 84
  • 70