ios Xcode MyProjectName-Bridging-Header.h 不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26096402/
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
Xcode MyProjectName-Bridging-Header.h does not exist
提问by user2408952
I want to start using Swift in my Objective-C project. So i added a swift class:
我想在我的 Objective-C 项目中开始使用 Swift。所以我添加了一个 swift 类:
import Foundation
@objc class System : NSObject {
@objc func printSome() {
println("Print line System");
}
}
And imported it into a .m file:
并将其导入到 .m 文件中:
#import "MyProjectName-Swift.h"
#import "MyProjectName-Swift.h"
When building my project i get the following error:
在构建我的项目时,我收到以下错误:
Bridging header 'PathToMyProject/MyProjectName-Bridging-Header.h' does not exist
NOTE: Under "Build Settings->Swift Compiler - Code Generation->Objective-C Briding Header" is set to MyProjectName-Bridging-Header.h
注意:在“Build Settings->Swift Compiler - Code Generation->Objective-C Briding Header”下设置为 MyProjectName-Bridging-Header.h
What should i do to solve this issue?
我应该怎么做才能解决这个问题?
Any help is much appreciated.
任何帮助深表感谢。
EDIT: Bridging-Header file: #if defined(__has_include) && __has_include() # include #endif
编辑:桥接头文件:#if defined(__has_include) && __has_include() #include #endif
#include <objc/NSObject.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#if defined(__has_include) && __has_include(<uchar.h>)
# include <uchar.h>
#elif __cplusplus < 201103L
typedef uint_least16_t char16_t;
typedef uint_least32_t char32_t;
#endif
#if !defined(SWIFT_PASTE)
# define SWIFT_PASTE_HELPER(x, y) x##y
# define SWIFT_PASTE(x, y) SWIFT_PASTE_HELPER(x, y)
#endif
#if !defined(SWIFT_METATYPE)
# define SWIFT_METATYPE(X) Class
#endif
#if defined(__has_attribute) && __has_attribute(objc_runtime_name)
# define SWIFT_RUNTIME_NAME(X) __attribute__((objc_runtime_name(X)))
#else
# define SWIFT_RUNTIME_NAME(X)
#endif
#if !defined(SWIFT_CLASS_EXTRA)
# define SWIFT_CLASS_EXTRA
#endif
#if !defined(SWIFT_PROTOCOL_EXTRA)
# define SWIFT_PROTOCOL_EXTRA
#endif
#if !defined(SWIFT_CLASS)
# if defined(__has_attribute) && __has_attribute(objc_subclassing_restricted)
# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_CLASS_EXTRA
# else
# define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_CLASS_EXTRA
# endif
#endif
#if !defined(SWIFT_PROTOCOL)
# define SWIFT_PROTOCOL(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) SWIFT_PROTOCOL_EXTRA
#endif
#if !defined(SWIFT_EXTENSION)
# define SWIFT_EXTENSION(M) SWIFT_PASTE(M##_Swift_, __LINE__)
#endif
#if !defined(OBJC_DESIGNATED_INITIALIZER)
# if defined(__has_attribute) && __has_attribute(objc_designated_initializer)
# define OBJC_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
# else
# define OBJC_DESIGNATED_INITIALIZER
# endif
#endif
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch"
#if defined(__has_feature) && __has_feature(modules)
#endif
#pragma clang diagnostic pop
回答by James Toomey
If the bridging file is created at the same level as the other classes, you might need to add the relative path, as these pictures show. Note here that the bridging file is created at the same level as the other classes:
如果桥接文件是在与其他类相同的级别创建的,您可能需要添加相对路径,如这些图片所示。请注意,桥接文件是在与其他类相同的级别创建的:
I have the name entered correctly in the Build Settings,
我在构建设置中正确输入了名称,
but the compiler doesn't find the file.
但编译器没有找到该文件。
Therefore, if I add the relative path from the root of the project (that is, I add ./ProjectName/BridgerFileName.h
),
因此,如果我从项目的根目录添加相对路径(即我添加./ProjectName/BridgerFileName.h
),
now it compiles and I can call a method in my Objective C class:
现在它可以编译了,我可以在我的 Objective C 类中调用一个方法:
回答by DonVaughn
I found that after creating the bridging header file manually and choosing the default name and location, the bridging header will be placed in the project directory, which is under the root directory.
我发现手动创建桥接头文件并选择默认名称和位置后,桥接头将放置在项目目录中,该目录位于根目录下。
This requires the following value for the setting: Targets > [Your App Target] > Build Settings > Swift Compiler - Code Generation > Objective-C Bridging Header:
这需要以下设置值:Targets > [Your App Target] > Build Settings > Swift Compiler - Code Generation > Objective-C Bridging Header:
$(SRCROOT)/$(PROJECT_NAME)/$(PROJECT_NAME)-Bridging-Header.h
Note that if your project is a swift module (framework) then, as pointed out in the comments, you might prefer:
请注意,如果您的项目是一个 swift 模块(框架),那么正如评论中所指出的,您可能更喜欢:
$(SRCROOT)/$(PROJECT_NAME)/$(SWIFT_MODULE_NAME)-Bridging-Header.h
回答by Suragch
For those who are removing the Bridging Header
对于那些正在删除桥接头的人
I was going the opposite way as most of the other answers here. I had been using a Bridging Header previously, but I didn't need it anymore. After I deleted it from my project I started getting the error mentioned in the question. I performed the following steps to solve my problem.
我与这里的大多数其他答案相反。我以前一直在使用桥接头,但我不再需要它了。从我的项目中删除它后,我开始收到问题中提到的错误。我执行了以下步骤来解决我的问题。
- Go to Targets > [Your App Target] > Build Settings > Swift Compiler - General > Objective-C Bridging Headerand delete the path. (Thanks to @Donamitefor the idea.) (You can just start typing "bridging" into the search box to find it.)
- Delete the derived date. Go to Xcode > Preferences > Locationsand click the gray arrow by the Derived Data folder. Then delete your project folder.
- 转到Targets > [Your App Target] > Build Settings > Swift Compiler - General > Objective-C Bridging Header并删除路径。(感谢@Donamite的想法。)(您只需在搜索框中输入“bridging”即可找到它。)
- 删除派生日期。转到Xcode > Preferences > Locations,然后单击 Derived Data 文件夹旁边的灰色箭头。然后删除您的项目文件夹。
回答by iOS
In Swift 4.1
在Swift 4.1 中
your project you don't have bridging-Header.h
file, but your project has that path. For this you need to delete that path...
你的项目没有bridging-Header.h
文件,但你的项目有那个路径。为此,您需要删除该路径...
Go to targets
file and select Build Settings
, ---->Swift Compiler - General
, and delete the bridging-Header.h
. Follow below screen shots....
转到targets
文件并选择Build Settings
, ----> Swift Compiler - General
,然后删除bridging-Header.h
. 按照下面的屏幕截图......
Delete the bridging-Header.h
file in Swift Compiler - General
bridging-Header.h
在 Swift Compiler - General 中删除文件
Now you got like this...
现在你变成这样了...
回答by Maninderjit Singh
To add Bridge File in Swift project.
在 Swift 项目中添加桥文件。
Step 1. Go to File > Add Cocoa with Objective-C File (For temporary Purpose)
步骤 1. 转到文件 > 使用 Objective-C 文件添加 Cocoa(临时用途)
Step 2. Then the following pop up will appear
Now press Create Bridging Header Button
现在按创建桥接标题按钮
DONE
YOU WILL GET BRIGDE FILE IN BUNDLE
THANKS
完成后,
您将获得捆绑的 BRIGDE 文件,
谢谢
回答by Srinivas Padidala
For me it helped to use $(SRCROOT)/$(PROJECT_NAME)/ in front of my bridging header file path
对我来说,在桥接头文件路径前使用 $(SRCROOT)/$(PROJECT_NAME)/ 很有帮助
回答by Vishnuvardhan
These are steps to create Bridging header.
这些是创建桥接头的步骤。
File->New->iOS->Header File, Give the bridging file name as like "yourProjectName-Bridging-Header.h"
Build-Settings->Objective-C Bridging Header, Just give the bridging header file name be like "ProjectName-Bridging-Header.h"
NOTE:Bridging header file should be located in the main root folder of the project where the ".xcodeproj" file located. If not move the Bridging header file to the root folder of the project. This way Xcode able to access the bridge file.
Build the project, and import necessary files in Bridging header.
File->New->iOS->Header File,给桥接文件名像“yourProjectName-Bridging-Header.h”
Build-Settings->Objective-C Bridging Header,只需将桥接头文件名命名为“ProjectName-Bridging-Header.h”
注意:桥接头文件应位于“.xcodeproj”文件所在项目的主根文件夹中。如果没有将 Bridging 头文件移动到项目的根文件夹。这样 Xcode 就可以访问桥文件了。
构建项目,并在 Bridging 标头中导入必要的文件。
回答by Antoine
For me it helped to use $(SRCROOT)
in front of my Objective-C bridging header path.
对我来说,它有助于$(SRCROOT)
在我的 Objective-C 桥接头路径前面使用。
$(SRCROOT)/swiftLibraries/swiftLibraries-Bridging-Header.h
回答by iHart
Follow the steps below:
请按照以下步骤操作:
- Delete bridging header file . . . (Maybe you create manually) and;
- Create new Swift file in Objective-C Project . . . (Not import, first create it)
- 删除桥接头文件。. . (也许您手动创建)和;
- 在 Objective-C 项目中创建新的 Swift 文件。. . (不是导入,先创建)
Maybe these two things will help solve your problem.
也许这两件事将有助于解决您的问题。
回答by A.G
The following worked for me:
以下对我有用:
- Bridging header file should be located in the main root folder of the project where the ".xcodeproj" file located. Move to project directory and drag and drop bridging header to root if it is inside any other folder.
- Correct spelling mistakes in header name.
- Clear Derived data
- Target -> Build Settings -> Swift Compiler : General -> Add Obj C Header name.
- Clean and run again.
- 桥接头文件应位于“.xcodeproj”文件所在项目的主根文件夹中。移动到项目目录并将桥接头拖放到根目录(如果它在任何其他文件夹中)。
- 更正标题名称中的拼写错误。
- 清除派生数据
- Target -> Build Settings -> Swift Compiler : General -> Add Obj C Header name。
- 清洁并再次运行。