找不到Project-Swift.h文件 [英] Project-Swift.h file not found

查看:51
本文介绍了找不到Project-Swift.h文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含几个文件的新Swift项目,我需要添加一些Objc代码.

I have a new Swift project with a few files, I've needed to add some Objc code.

Build Settings 中,我的 Objective-C生成的接口头名称 MyProject-Swift.h

产品模块名称产品名称都是MyProject.

Product Module Name and Product Name are both MyProject.

我的 Objective-C桥接标头 MyProject/MyProject-Bridging-Header.h

我的 Bridging Header 的内容是:

#ifndef MyProject_Bridging_Header_h
#define MyProject_Bridging_Header_h

#import "Blakey.h"

#endif

Blakey.h 非常简单:

@import Foundation;

#import "MyProject-Swift.h"
@class KeyPair;

@interface Blakey: NSObject

- (void)createKeyPairForSeed:(NSString *)seed;

@end

Blakey.m

#import <Foundation/Foundation.h>
#import "Blakey.h"

@implementation Blakey


- (void)createKeyPairForSeed:(NSString *)seed;
{

}

@end

(旁注:我知道我的函数返回一个void,一旦解决此问题,它将在以后更改,因此它将返回实际值)

(side note: I'm aware my function returns a void, that will be changed later once this issue is fixed so it returns an actual value)

为什么Xcode在 Blakey.h 中的 #import"MyProject-Swift.h" 处引发错误?

Why is Xcode throwing an error at the #import "MyProject-Swift.h" in Blakey.h?

推荐答案

Project-Swift.h 是Xcode在成功编译项目后自动生成的文件.此处是成功编译一词,如果您的项目有任何编译错误,将不会生成 Project-Swift.h 文件.因此,在某种程度上,它变成了僵局.Bestway注释掉所有有编译错误的行,然后设法使其编译没有任何错误.仅在生成 Project-Swift.h 之后.

Project-Swift.h is a file auto generated by Xcode on successful compilation of the project. Catch here is the word successful compilation If your project has any compilation error Project-Swift.h file will not be generated. So in a way it becomes a deadlock. Bestway comment out all the lines that have compilation error and then manage to get it compile without any errors. Only after that Project-Swift.h will be generated.

其他信息,如果您打开 Project-Swift.h 文件,并且偶然发现您的swift类没有导入到那,那是因为 Project-Swift.h 仅导入从 NSObject 扩展的类,因此不会导入普通的Swift类.

Additional information, Once the Project-Swift.h file is generated if you open it and if you happened to see that your swift class is not imported there thats because Project-Swift.h imports only the classes that extends from NSObject So plain Swift classes will not be imported.

问题:

您需要在.m文件而不是.h文件中导入 Project-Swift.h .因此,将您的Blakey修改为

You need to import Project-Swift.h in .m file and not .h file. So modify your Blakey as

#import <Foundation/Foundation.h>
#import "Blakey.h"
#import "MyProject-Swift.h"

@implementation Blakey


- (void)createKeyPairForSeed:(NSString *)seed;
{

}

最后从 Blakey.h

@import Foundation;

@class KeyPair;

@interface Blakey: NSObject

- (void)createKeyPairForSeed:(NSString *)seed;

@end

这篇关于找不到Project-Swift.h文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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