UIView.convert unsupported in iOS7

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

Replies

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.

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)

}

}

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"

it's a bug in the compiler


see https://bugs.swift.org/browse/SR-3157 to which I've attached a sample project

"Looks like a type checker bug—it's picking the version of convert that takes a UICoordinateSpace rather than a UIView"


It is not possible to debug ios7 or deploy on ios7 device since the runtime was not included in Xcode8

It is just possible to archive and install, which means ios7 is actually not supported for development without an official announcement (at least I didn't find one...)

When I use -convert(_:to:) in Swift 3, if you option + click this method, it shows that Avaliability is iOS (8.0 and later).