I decided to implement a few views using SwiftUI in my app. The app is backwards compatible to 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?
So sorry, but I don't think SwiftUI Will work on older versions then iOS 13. Found this stack link if you want more details Is SwiftUI backwards-compatible with iOS 12.x and older?
You can also mark SwiftUI.framwerk as optional in Build Phases. Detailed Instruction below.
Turns out this is a known issue and apple introduced a new build setting flag to handle it
Adding
-weak_framework SwiftUI
toOther Linker Flags
fixed my issue