我正在构建一个cocopod,它基本上包含一个框架(私有源代码)和一个依赖于这个框架的视图(开放源代码),所有这些都是用Objective-C制作的。
在podspec中,我有以下几行:
spec.vendored_frameworks = 'MyPod/Framework/MyFramework.framework'
spec.source_files = ['MyPod/UI/Views/MyView.{h,m}']
当使用use_frameworks!
语法时,我不能使用#import MyFramework
我只是不明白发生了什么。
而且,当我删除spec.source_files
行时,我可以使用#import MyFramework
,它工作得很完美,但当然不能使用MyView
。
我哪里做错了?
4条答案
按热度按时间woobm2wo1#
对于今天遇到这个问题的任何人:这是CocoaPods中的一个已知问题,Github here和here上提出了一些问题来讨论这个问题。
建议的解决方法是将您的podspec拆分为两个:一个podspec只包含您的
vendored_frameworks
,另一个podspec只包含使用该框架的source_files
。Github上的用户crsantos已经发布了一个关于这个变通方案的例子,我在下面复制了两个单独的播客规范。
供应商框架podspec:
源文件podspec。注意对供应商框架podspec的依赖性。
lymnna712#
如果使用
use_frameworks!
,pod本身将成为一个框架,因此应该使用#import MyPod
而不是#import MyFramework
,然后使用MyView
。如果需要,也可以查看
public_header_files
。r6l8ljro3#
由于项目的pod现在是一个框架,您可以使用**
@import
**MyFramework
尝试importing it as a module。但是,如果这不起作用,那么尝试备份您的项目,然后运行
pod deintegrate && pod install
。另外,this question非常相似,它的一些注解和答案可能会有帮助。hof1towb4#
虽然shorking的答案在技术上是正确的,但有一种方法可以将
source_files
和vendored_frameworks
结合起来,解决方案是同时使用preserve_paths
来指向供应商框架的位置。