Optional linking for Swift Combine.framework in Xcode 11

耗尽温柔 提交于 2019-12-21 04:09:13

问题


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.

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


回答1:


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.

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:


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




回答3:


  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.
  2. Drag Combine.framework from the Finder window and drop it into the frameworks list, then choose Optional from the status popup.
  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).
  4. If you get a weird relative path (starting with ../iPhoneOS.sdk/), then open the project in a text editor and fix that manually.


来源:https://stackoverflow.com/questions/57168931/optional-linking-for-swift-combine-framework-in-xcode-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!