[英]Optional linking for Swift Combine.framework in Xcode 11
Our application supports iOS 11 and higher.我们的应用程序支持 iOS 11 及更高版本。 In iOS 13 we use
SwiftUI
+ Combine
在 iOS 13 中,我们使用
SwiftUI
+ Combine
we wrap import of SwiftUI
or Combine
framework with correspondent check #if canImport(SwiftUI)
or #if canImport(Combine)
.我们将
SwiftUI
或Combine
框架的导入与相应的检查#if canImport(SwiftUI)
或#if canImport(Combine)
#if canImport(SwiftUI)
。 If we run our app from Xcode 11 under iOS 12 we have error dyld: Library not loaded: /System/Library/Frameworks/Combine.framework/Combine
如果我们在 iOS 12 下从 Xcode 11 运行我们的应用程序,
dyld: Library not loaded: /System/Library/Frameworks/Combine.framework/Combine
出现错误dyld: Library not loaded: /System/Library/Frameworks/Combine.framework/Combine
We fixed same issue for SwiftUI by linking it optionally.我们通过选择性链接 SwiftUI 修复了相同的问题。
But we can't make same for Combine as it can not be even selected for linking但是我们不能为Combine 做同样的事情,因为它甚至不能被选中进行链接
You can add the linker flags explicitly to optionally link Combine when it is available in the build settings.当它在构建设置中可用时,您可以显式添加链接器标志以选择性地链接Combine。 In the Xcode Build Settings add -weak_framework Combine to Other Linker Flags .
在 Xcode Build Settings 中添加-weak_framework Combine到Other Linker Flags 。
Or add the following line in your XCConfig file:或者在您的 XCConfig 文件中添加以下行:
OTHER_LDFLAGS = -weak_framework Combine
or if you still want to support building with older Xcode versions:或者如果您仍想支持使用较旧的 Xcode 版本进行构建:
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
../iPhoneOS.sdk/
), then open the project in a text editor and fix that manually.../iPhoneOS.sdk/
),然后在文本编辑器中打开项目并手动修复它。Inspired by @nschmidt answer, but with solution that will work both for Xcode 10 and Xcode 11灵感来自@nschmidt 答案,但解决方案适用于 Xcode 10 和 Xcode 11
Add this to xcconfig将此添加到 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或者添加
OTHER_LDFLAGS_XCODE_SPECIFIC_1100
作为自定义构建设置
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.就我们今天所了解的而言,如果您至少使用 Xcode 11.3.1 进行构建,则无需采用任何解决方法。 It works out of box even without mentioning SwiftUI or Combine in any linking related configuration/build phase and etc.
即使没有在任何链接相关的配置/构建阶段等中提及 SwiftUI 或组合,它也可以开箱即用。
It turns out to be a bug in (at least) Xcode-11.1, that resulted in Combine framework not weakly linked by default.结果证明是(至少)Xcode-11.1 中的一个错误,导致默认情况下Combine 框架没有弱链接。 It looks like the bug was fixed at least in Xcode-11.3.1 - it does weakly link Combine by default.
看起来这个错误至少在 Xcode-11.3.1 中得到了修复 - 默认情况下它确实弱链接 Combine 。 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
苹果人的一些相关报告和回答在这里: https : //forums.swift.org/t/why-swift-package-manager-does-not-support-weak-linking-weak-framework-swiftui/31418/2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.