dyld: Library not loaded SwiftUI when app runs on iOS 12 using @available(iOS 13.0, *)
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.
- Select your project file in the Xcode navigator.
- Select your app target (or whichever target you're using SwiftUI from).
- Select the “Build Phases” tab, then “Link Binary With Libraries” section.
- Click the + button under the list that appears.
- Type “SwiftUI” into the search field of the popup sheet, select “SwiftUI.framework,” and click “Add.”
- On the new row in the table, click the “Required” popup button in the last column. Change the value to “Optional.”