2
votes

I have several UIKit-based iOS apps that are already distributed on the AppStore that I would like to update, and I consider switching to SwiftUI.

My question is: what would happen for users who already own the app but are running iOS versions older than iOS13? Will the app become totally unavailable for them or will they keep the ability to use their old UIKit version?

Thank you very much !

2

2 Answers

3
votes

To allow SwiftUI in your app you’ll have to allow support for iOS 13 and above. You can do so by either changing the support of you app to iOS 13 and above or use ‘ @available(iOS 13.0, *)’ decorator around you new code. In the first case users will keep their ability to use the latest version installed on their device. They won’t be able to update to new versions. On the later case, which will require more handling from you as a developer. Users will be able to continue and update the application and use the alternative code you provided

2
votes

You can use compiler directives to create SwiftUI views for users running iOS 13, and provide UIKit alternatives for iOS 12 or lower.

For example, you can mark your SwiftUI view as only available from iOS 13:

@available(iOS 13.0, *)
struct MyView: View {
  // ...
}

And create a UIKit alternative:

class MyViewController: UIViewController {
  // ...
}

Then, when it comes to presenting the view, you can conditionally show the correct version:

let destinationVC: UIViewController

if #available(iOS 13.0, *) {
  destinationVC = UIHostingController(rootView: MyView())
} else {
  destinationVC = MyViewController()    
}
self.present(destinationVC, animated: true, completion: nil)