skip to Main Content

We have an app with a lot of functionality. We have decided to move slowly to SwiftUI, and I’ve implemented one of the views as a SwiftUI view. We support older iOS versions (from 10.0), so I had to add a lot of if #available(iOS 13.0, *) and @available(iOS 13.0, *) wherever needed around. The app runs fine on the simulators with different iOS versions. I can install it on my iPhone 11 with iOS 14, but when I try to archive the app I get a lot of errors, like:

  • Cannot find ‘UIHostingController’ in scope
  • Unknown attribute ‘State’

and other stuff related to SwiftUI. It seems that it can’t archive older versions.

I triple checked that all the classes and calls that relates to SwiftUI are tagged as only available for iOS 13. The application runs correctly on the iOS 12.4 simulator.

Any ideas?

2

Answers


  1. Chosen as BEST ANSWER

    I haven't properly solved the issue, but Change the iOS Deployment Target to iOS 11.0 fixed it.


  2. Changing the deployment target to iOS 11 as @Olav mentioned fixed it. However, digging a little deeper, it seems it’s because SwiftUI doesn’t build for armv7 . Setting the minimum to iOS 11 excludes armv7 automatically.

    This issue can be resolved by either:

    1. Setting the minimum deployment target to iOS 11.0 as mentioned by @Olav
    2. Manually limiting your project architecture to exclude armv7
      • project -> info -> architectures -> excluded architectures -> add armv7
      • will of course prevent your app from running on iPhone 5 / 5C, iPad 4th gen/retina
    3. Wrapping all SwiftUI code in the compiler directive: #if !arch(arm) / #endif
      • arch(arm) matches armv7, arch(arm64) matches arm64 & arm64e
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search