ios - Xcode MyProjectName-Bridging-Header.h 不存在

标签 ios objective-c xcode swift

我想在我的 Objective-C 项目中开始使用 Swift。所以我添加了一个 swift 类:

import Foundation
@objc class System : NSObject {
    @objc func printSome() {
        println("Print line System");
    }
}

并将其导入到 .m 文件中:

#import "MyProjectName-Swift.h"

在构建我的项目时,我收到以下错误:

Bridging header 'PathToMyProject/MyProjectName-Bridging-Header.h' does not exist

注意:在“build设置->Swift 编译器-代码生成->Objective-C Briding Header”下设置为 MyProjectName-Bridging-Header.h

我应该怎么做才能解决这个问题?

非常感谢任何帮助。

编辑:桥接头文件: #if 定义(__has_include) && __has_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

最佳答案

如果桥接文件是在与其他类相同的级别创建的,您可能需要添加相对路径,如这些图片所示。请注意,桥接文件是在与其他类相同的级别创建的: enter image description here

我在build设置中正确输入了名称, enter image description here

但编译器没有找到该文件。 enter image description here

因此,如果我从项目的根目录添加相对路径(即添加./ProjectName/BridgerFileName.h), enter image description here

现在它编译了,我可以在我的 Objective C 类中调用一个方法: enter image description here

关于ios - Xcode MyProjectName-Bridging-Header.h 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26096402/

相关文章:

xcode - 无效的权利 iOS SDK 4.1

javascript - 如何检测用户何时触摸菜单或其子项以外的其他内容?

iphone - 尝试创建一个高度自定义的 TableView

objective-c - 即使导入了 <CoreLocation/CoreLocation.h> 也找不到 CLLocation

ios - iOS 中字体 Glyph Ascender 和 Descender 之间的关系是什么?

xcode - 实现 Yosemite 提醒/注释/消息/联系人样式窗口

ios - SwiftUI:如何将 CoreData 与动态过滤器相加?

ios - 在基于本地 Mac 的 IPv6 DNS64/NAT64 网络中检查到 0.0.0.0 的可达性时不会发生错误

iphone - 当用户滚动到tableView的底部时,如何向UITableView添加10条记录

ios - Shell 脚本调用错误 - Xcode 6