Xcode MyProjectName-Bridging-Header.h不存在 [英] Xcode MyProjectName-Bridging-Header.h does not exist

查看:349
本文介绍了Xcode MyProjectName-Bridging-Header.h不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to start using Swift in my Objective-C project. So i added a swift class:

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

并将其导入.m文件:

#importMyProjectName-Swift.h

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

When building my project i get the following error:

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

注意:在Build Settings-> Swift Compiler - Code Generation-> Objective-C Briding Header下设置为MyProjectName-Bridging-Header.h

NOTE: Under "Build Settings->Swift Compiler - Code Generation->Objective-C Briding Header" is set to MyProjectName-Bridging-Header.h

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

What should i do to solve this issue?

任何非常感谢帮助。

EDIT:Bridging-Header文件:
#if defined(__ has_include)&& __has_include()
#include
#endif

Bridging-Header file: #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


推荐答案

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

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:

我在Build Settings中正确输入了名称,

I have the name entered correctly in the Build Settings,

但编译器找不到该文件。

but the compiler doesn't find the file.

因此,如果我从项目的根添加相对路径(也就是说,我添加 ./ ProjectName / BridgerFileName.h ),

Therefore, if I add the relative path from the root of the project (that is, I add ./ProjectName/BridgerFileName.h),

现在它编译,我可以调用一个方法我的目标C类:

now it compiles and I can call a method in my Objective C class:

这篇关于Xcode MyProjectName-Bridging-Header.h不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆