I decided to implement a few views using SwiftUI in my app. The app is backward compatible with iOS 12.
Everything works perfectly until I run it on an iOS 12 device. The app crashes immediately and the warning I get says SwiftUI cannot be loaded.
dyld: Library not loaded: /System/Library/Frameworks/SwiftUI.framework/SwiftUI Referenced from: /var/containers/Bundle/Application/MyApp.app/MyApp Reason: image not found
I'm using @available(iOS 13.0, *) in all the correct places and there are no compiler warnings and the app runs perfectly on iOS 13
How can I get this to work for iOS 12?
SwiftUI runs on iOS 13, macOS 10.15, tvOS 13, and watchOS 6, or any future later versions of those platforms. This means if you work on an app that must support iOS N-1 or even N-2 – i.e., the current version and one or two before that – then you will be limited in terms of the features you can offer.
SwiftUI 3 is still in beta and will become available with iOS 15 and Xcode 13. There is much more to SwiftUI 3 than can be covered here, so do not miss the What's new in SwiftUI video from WWDC 2021 if you are interested.
Xcode and Swift are both software development products developed by Apple. Swift is a programming language used to create apps for iOS, macOS, tvOS, and watchOS. Xcode is an Integrated Development Environment (IDE) that comes with a set of tools that helps you build Apple-related apps.
Turns out this is a known issue and apple introduced a new build setting flag to handle it
Apps containing SwiftUI inside a Swift package might not run on versions of iOS earlier than iOS 13. (53706729)
Workaround:
When back-deploying to an OS which doesn't contain the SwiftUI framework, add the -weak_framework SwiftUI flag to the Other Linker Flags setting in the Build Settings tab. See Frameworks and Weak Linking for more information on weak linking a framework. This workaround doesn't apply when using dynamically linked Swift packages which import SwiftUI.
Adding -weak_framework SwiftUI
to Other Linker Flags
fixed my issue
You can also mark SwiftUI.framwerk as optional in Build Phases. Detailed Instruction below.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With