ios - 在我的 podspec 中设置 DEFINES_MODULE = YES 有什么缺点吗?

标签 ios cocoapods

一些 Cocoapods,例如YLTableView , 不要将 'DEFINES_MODULE' => 'YES' 设置为它们的 pod_target_xcconfig 的一部分。这意味着,例如,import YLTableView 在 Swift 中不起作用,除非您像这样在 Podfile 中设置 :modular_headers => true:

pod 'YLTableView', '~> 2.2.0', :modular_headers => true

如果我正在编写 podspec,有什么理由不应该像这样在我的配置中包含 DEFINES_MODULE?

ss.pod_target_xcconfig = { "DEFINES_MODULE" => "YES" }

在我看来,这没有任何负面影响,它使 Swift 用户可以更轻松地使用我的库。

最佳答案

存在一个已知问题(有解决方法):https://github.com/CocoaPods/CocoaPods/issues/7584 .这可能会导致用户在其预编译 header (*.pch) 中直接导入您的 Objective-C 库 header 时出现问题。您可以通过在 lib 源文件中包含一个空的 swift 文件来解决它。 future 版本的 CocoaPods 中可能会有一个干净的修复程序。


否则,没有真正的缺点。它在构建时为导入启用更严格的搜索路径,这意味着:

  • 要么构建,要么像以前一样工作(作为奖励,你现在可以在 ObjC 中使用 @import 或在 Swift 中使用 import 找到它)
  • 要么它不再构建,因此您不能再发布 podspec

来自 the blog post regarding CocoaPods 1.5.0 release :

[...] CocoaPods allowed any pod to import any other pod with un-namespaced quote imports.

For example, pod B could have code that had a #import "A.h" statement, and CocoaPods will create build settings that will allow such an import to succeed. Imports such as these, however, will not work if you try to add module maps to these pods. We tried to automatically generate module maps for static libraries many years ago, and it broke some pods, so we had to revert.

In this release, you will be able to opt into stricter header search paths (and module map generation for Objective-C pods). As a pod author, you can add 'DEFINES_MODULE' => 'YES' to your pod_target_xcconfig. [...]

关于ios - 在我的 podspec 中设置 DEFINES_MODULE = YES 有什么缺点吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51227921/

相关文章:

ios - 以下标签被截断了?? .关于如何显示 MultiLine UILabel 有什么建议吗?

ios - 通过cocoapod安装CorePlot 2.0失败

ios - 将 Flutter 模块暴露为 IOS 框架会导致 "Failed to find assets path for "Frameworks/App.framework/flutter_assets"

ios - 如何在Pod项目ViewController中导入AppDelegate.h文件?

iphone - 检查 iOS 中 Safari 的内存使用情况

ios - 如何在UIImage Picker中隐藏前置摄像头?

ios - Crashlytics 不会捕捉到内存不足

ios - 从 NSMutableArray 中检索对象

ios - 在 podfile 中添加 'use_frameworks!' 会破坏应用程序

ios - 为什么在我的框架中我可以访问 Storyboard_a.storyboard 而无法访问 Storyboard_b.storyboard?