ios Xcode 7 无法从框架中找到头文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30762492/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 06:20:35  来源:igfitidea点击:

Xcode 7 can't find header files from framework

iosxcodepassslot

提问by somepers

I'm trying to add PassSlot into my project, but it says it can't find the .h file. I'm following everything correctly from here: https://github.com/passslot/passslot-ios-sdk

我正在尝试将 PassSlot 添加到我的项目中,但它说它找不到 .h 文件。我从这里正确地关注所有内容:https: //github.com/passslot/passslot-ios-sdk

Is this an Xcode 7 problem? It was working fine and now that I opened the project in Xcode 7, it is giving me this problem. I reopened it on Xcode 6 and it starts showing the problem as well.

这是 Xcode 7 的问题吗?它工作正常,现在我在 Xcode 7 中打开了这个项目,它给了我这个问题。我在 Xcode 6 上重新打开它,它也开始显示问题。

回答by Spriter

I think Dinesy is right. This solves the problem for me.

我认为Dinesy是对的。这为我解决了问题。

I've noticed that Xcode7 doesn't automatically fill in the required Framework search paths when you import a 3rd party one (I believe Xcode6 did do this). Check if yours are empty by going to Project -> Build Settings -> Search Paths -> Framework Search Paths. Fill it in with wherever your Frameworks live. If it's under your project you can use $(PROJECT_DIR)

我注意到当您导入第 3 方时,Xcode7 不会自动填充所需的框架搜索路径(我相信 Xcode6 确实这样做了)。通过转到 Project -> Build Settings -> Search Paths -> Framework Search Paths 检查你的是否为空。在您的框架所在的任何地方填写它。如果它在您的项目下,您可以使用 $(PROJECT_DIR)

回答by BLC

Replacing #import "Headerfile.h"with #import <Framework/Headerfile.h>worked for me.

更换#import "Headerfile.h"#import <Framework/Headerfile.h>为我工作。

回答by mike_manila

When you Drag & Drop the required framework to your Frameworks folder, Tick on "Destination: Copy items if needed"

当您将所需的框架拖放到您的 Frameworks 文件夹时,勾选“目标:如果需要,复制项目”

Then you would be able to reference it properly now.

那么你现在就可以正确引用它了。

Screenshot

截屏

回答by Gowiem

Just ran into this with Xcode 7 and I ended up having to copy the 3rd party Framework (and bundle) file into my project's main directory before dragging it into the Xcode project. This allowed it to add the correct Framework search path and no longer gave me any problems.

刚刚使用 Xcode 7 遇到了这个问题,我最终不得不将第 3 方框架(和包)文件复制到我的项目的主目录中,然后再将其拖到 Xcode 项目中。这允许它添加正确的框架搜索路径并且不再给我任何问题。

回答by Luciano

Just hit this problem myself after making a new test target in Objective-C.

在 Objective-C 中创建一个新的测试目标后,我自己就遇到了这个问题。

One thing to remember is that under some circumstances, each test target must be listed in the Podfilewith poddependencies. If the Podfileonly associates the project with the pods, it may not find the pod header files.

有一点要记住的是,在某些情况下,每个测试的目标,必须在上市Podfilepod依赖。如果Podfile只将项目与 pod 关联,则可能找不到 pod 头文件。

Here's an example of a more complex Podfilefrom the cocoapods docs.

下面是一个更复杂的例子Podfile,从该的CocoaPods文档

target 'MyApp' do
  pod 'ObjectiveSugar', '~> 0.5'

  target "MyAppTests" do
    inherit! :search_paths
    pod 'OCMock', '~> 2.0.1'
  end
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    puts "#{target.name}"
  end
end

回答by Zaq

In my case, using CocoaPods, Xcode was building fine, but a command line build couldn't locate the framework headers.

就我而言,使用 CocoaPods,Xcode 构建良好,但命令行构建无法找到框架标头。

The solution was to build the workspace, not the project!

解决方案是构建工作区,而不是项目!

回答by Robin Stewart

I ran into this error when trying to link to my own custom framework. The problem was that I hadn't set up my framework to export the needed headers. To do so:

我在尝试链接到我自己的自定义框架时遇到了这个错误。问题是我没有设置我的框架来导出所需的标题。这样做:

  1. Select each header file you want to make available, go to the File Inspector > Target Membership, and make sure the target is checked and set to "Public".
  2. In the MyFrameworkName.h top-level file, import each header file you want to make available: e.g. #import <MyFrameworkName/MyPublicHeader.h>
  1. 选择您想要提供的每个头文件,转到 File Inspector > Target Membership,并确保选中目标并将其设置为“Public”。
  2. 在 MyFrameworkName.h 顶级文件中,导入您想要提供的每个头文件:例如 #import <MyFrameworkName/MyPublicHeader.h>

回答by lytridic

Cleaning the project and restarting XCode sometimes helps

清理项目并重新启动 XCode 有时会有所帮助