20

Our application supports iOS 11 and higher. In iOS 13 we use SwiftUI + Combine

we wrap import of SwiftUI or Combine framework with correspondent check #if canImport(SwiftUI) or #if canImport(Combine). If we run our app from Xcode 11 under iOS 12 we have error dyld: Library not loaded: /System/Library/Frameworks/Combine.framework/Combine

We fixed same issue for SwiftUI by linking it optionally.

enter image description here

But we can't make same for Combine as it can not be even selected for linking

enter image description here

3
  • Since we're talking extremely beta, maybe you can simply change it to look for iOS 13? I'm pretty sure - not 100% - that both SwiftUI and Combine** require not only the OS versions coming this fall but also Swift 5.1`. Checking for OS versions should work for now. And if not? File a bug report.
    – user7014451
    Commented Jul 23, 2019 at 18:30
  • It works perfect on iOS 13 with same build settings. The issue here that Combine.framework even and can not be selected from list can not be marked as optional. Will prepare small demo project for this Commented Jul 23, 2019 at 22:07
  • I see. It really feels like (to me) that the easiest way to proceed is to make an iOS 13 fork in your app. Certainly not ideal, but you've already seen the headache of going any other way.
    – user7014451
    Commented Jul 23, 2019 at 22:16

4 Answers 4

17

You can add the linker flags explicitly to optionally link Combine when it is available in the build settings. In the Xcode Build Settings add -weak_framework Combine to Other Linker Flags.

build settings Ohter Linker Flags "-weak_framework Combine"

Or add the following line in your XCConfig file:

OTHER_LDFLAGS = -weak_framework Combine

or if you still want to support building with older Xcode versions:

OTHER_LDFLAGS[sdk=iphoneos13.0] = -weak_framework Combine
OTHER_LDFLAGS[sdk=iphonesimulator13.0] = -weak_framework Combine

OTHER_LDFLAGS[sdk=watchos6.0] = -weak_framework Combine
OTHER_LDFLAGS[sdk=watchsimulator6.0] = -weak_framework Combine

OTHER_LDFLAGS[sdk=appletvos13.0] = -weak_framework Combine
OTHER_LDFLAGS[sdk=appletvsimulator13.0] = -weak_framework Combine

OTHER_LDFLAGS[sdk=macosx10.15] = -weak_framework Combine
2
  1. Navigate to Build Phases tab of your target settings, expand Link binaries with libraries section and right click on SwiftUI.framework, then select Show in Finder.
    Reveal SwiftUI.framework in Finder
  2. Drag Combine.framework from the Finder window and drop it into the frameworks list, then choose Optional from the status popup.
    Drag&Drop Combine.framework from Finder
  3. Select the Combine.framework item in the project explorer (right window pane) and choose Relative to SDK from the Location popup in the inspector (left window pane).
    Specify location relative to SDK
  4. If you get a weird relative path (starting with ../iPhoneOS.sdk/), then open the project in a text editor and fix that manually.
    Fix relative path in project file
1
  • 1
    Nice! Step 4 means editing path to System/Library/Frameworks/Combine.framework
    – hstdt
    Commented Dec 17, 2019 at 3:12
1

Inspired by @nschmidt answer, but with solution that will work both for Xcode 10 and Xcode 11

Add this to xcconfig

 OTHER_LDFLAGS_XCODE_SPECIFIC_1100 = -weak_framework Combine -weak_framework SwiftUI

 OTHER_LDFLAGS = $(inherited) ${OTHER_LDFLAGS_XCODE_SPECIFIC_$(XCODE_VERSION_ACTUAL)}

Or add OTHER_LDFLAGS_XCODE_SPECIFIC_1100 as custom build setting

1

As far as we figured it out today, there's no need to employ any workaround if you use at least Xcode 11.3.1 for building. It works out of box even without mentioning SwiftUI or Combine in any linking related configuration/build phase and etc.

It turns out to be a bug in (at least) Xcode-11.1, that resulted in Combine framework not weakly linked by default. It looks like the bug was fixed at least in Xcode-11.3.1 - it does weakly link Combine by default. Some related report and answer from Apple folks are here: https://forums.swift.org/t/why-swift-package-manager-does-not-support-weak-linking-weak-framework-swiftui/31418/2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.