Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

ios - Project-Swift.h file not found

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

In Build Settings, my Objective-C Generated Interface Header Name is MyProject-Swift.h

Product Module Name and Product Name are both MyProject.


My Objective-C Bridging Header is MyProject/MyProject-Bridging-Header.h

The contents of my Bridging Header are:

#ifndef MyProject_Bridging_Header_h
#define MyProject_Bridging_Header_h

#import "Blakey.h"

#endif

Blakey.h is pretty simple:

@import Foundation;

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

@interface Blakey: NSObject

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

@end

And Blakey.m

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

@implementation Blakey


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

}

@end

(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)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.

ISSUE:

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;
{

}

Finally remove #import "MyProject-Swift.h" from Blakey.h

@import Foundation;

@class KeyPair;

@interface Blakey: NSObject

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

@end

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...