6 Replies
      Latest reply: Nov 12, 2016 1:08 PM by yasmin777 RSS
      yasmin777 Level 1 Level 1 (0 points)

        We are converting an iOS app from swift 2.3 to swift 3 and have stumbled upon a problem.

        Our app supports iOS7 and on.

        UIView.convertRect has changed to convert, but this function is not supported in iOS7.

        We are also not able to put it into an available case since the compiler does not identify it.

        Any help will be appreciated

        • Re: UIView.convert unsupported in iOS7
          KMT Level 8 Level 8 (9,350 points)

          In that example, you may need to choose between swift 3 and legacy support for the (very?) small number of iOS7 users still out there.

          • Re: UIView.convert unsupported in iOS7
            yasmin777 Level 1 Level 1 (0 points)

            ok - solved this by creating an objective c method with convertRect and used it via bridging header to swift

            any cleaner solution would be most appreciated

             

            MyUIView.m

            + (CGRect)view:(nullable UIView *)view1 convertRect:(CGRect)rect toView:(nullable UIView *)view2 {

                return [view1 convertRect:rect toView:view2];

            }

             

            UsingMyUIView.swift

            func someFunc() {

                    let v1 = UIView()

                    let v2 = UIView()

                    let theRect = CGRect(x: 0, y: 0, width: 10, height: 10)

                  

                    var rect: CGRect

                    if #available(iOS 8.0, *) {

                        rect = v1.convert(theRect, to: v2)

                    }

                    else {

                        rect = MyUIView.view(v1, convert: theRect, to: v1)

                    }

            }

            • Re: UIView.convert unsupported in iOS7
              eskimo Apple Staff Apple Staff (7,550 points)

              UIView.convertRect has changed to convert, but this function is not supported in iOS7.

              What makes you say that?  Are you hitting a compilation problem?  Or a runtime problem?

              FYI, I created a simple test app, set the deployment target to iOS 7, added the following code to my main view controller, and it compiles just fine.

              override func viewDidLoad() {
                  super.viewDidLoad()
                  self.view.convert(CGRect.zero, to: self.view)
              }
              

              I don’t see any indication that -convertRect:toView: is unavailable on iOS 7, it’s just that the Swift name for it has changed to convert(_:to:) with Swift 3.

              ps How are you debugging this on iOS 7?  Last time I tried, Xcode 8 didn’t support iOS 7 on-device debugging or the iOS 7 simulator.

              Share and Enjoy

              Quinn “The Eskimo!”
              Apple Developer Relations, Developer Technical Support, Core OS/Hardware
              let myEmail = "eskimo" + "1" + "@apple.com"