xcode Cocoapods 将框架导入源代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16027798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cocoapods importing a framework to source code
提问by johngraham
In my cocoapod for iOS, I have a essentially items:
在我的 iOS cocoapod 中,我有一个本质上的项目:
- Open-source classes (.m & .h files)
- MyFramework.framework (.framework directory, header files, and .bundle for resources)
- 开源类(.m 和 .h 文件)
- MyFramework.framework(.framework 目录、头文件和资源的 .bundle)
One of the open-source classes calls import <MyFramework.MyFramework.h>so it can use the components of MyFramework in its implementation. But because of this, I'm having trouble getting the podspec to pass the spec lint test (pod spec lint MyCocoapod.podspec). When I run the spec lint validation, it says:
其中一个开源类调用,import <MyFramework.MyFramework.h>因此它可以在其实现中使用 MyFramework 的组件。但正因为如此,我无法让 podspec 通过 spec lint 测试 ( pod spec lint MyCocoapod.podspec)。当我运行规范 lint 验证时,它说:
ERROR | [iOS] [xcodebuild] .../MyFile.h:54:9: fatal error: 'MyFramework/MyFramework.h' file not found
ERROR | [iOS] [xcodebuild] .../MyFile.h:54:9: fatal error: 'MyFramework/MyFramework.h' file not found
While investigating, I noticed that the podspec does pass the spec lint validation if I remove that open-source class in the podspec's source_files section, s.source_files = 'MyFiles.{h,m}'. Any idea why my class can't import my custom framework during the spec lint validation?
在调查时,我注意到如果我删除 podspec 的 source_files 部分中的那个开源类,podspec 确实通过了规范 lint 验证s.source_files = 'MyFiles.{h,m}'。知道为什么我的班级在规范 lint 验证期间无法导入我的自定义框架吗?
The relevant code in the podspec looks like this:
podspec 中的相关代码如下所示:
s.preserve_paths = 'myframework/MyFramework.framework'
s.frameworks = 'Foundation', 'MyFramework'
s.xcconfig = { 'FRAMEWORK_SEARCH_PATHS' => '$(SRCROOT)/myframework/' }
s.public_header_files = 'MyFramework.framework/Headers/*.h', 'SourceCode/*.h'
s.source_files = 'SourceCode/*.{h,m}' # Crashes here - Source_file imports MyFramework.h. If I take this out, it passes spec lint validation
回答by Keith Smiley
EDITThis process is now entirely handled by the vendored_frameworksoption. This handles preserving the paths, the framework search paths, and linking to the project.
编辑此过程现在完全由vendored_frameworks选项处理。这处理保留路径、框架搜索路径和链接到项目。
回答by BigCheesy
To include a framework you can use:
要包含一个框架,您可以使用:
s.vendored_frameworks = 'path/to/SomeFramework.framework'
s.vendored_frameworks = 'path/to/SomeFramework.framework'
To include bundle files do:
要包含捆绑文件,请执行以下操作:
s.resources ='path/to/SomeBundle.bundle'
s.resources ='path/to/SomeBundle.bundle'

