Xcode 8与混合Swift和Objective-c项目生成“模块化-Swift”。h”头未找到

时间:2022-09-07 08:30:32

I have a project with mixed Swift and Objective-C in Xcode 8 that uses the generated "ModuleName-Swift.h" header file to import swift into Objective-c classes, but the preprocessor is not able to find the generated header file and throws an error on the import.

我有一个在Xcode 8中使用混合Swift和Objective-C的项目,它使用生成的“模块化Swift”。h"头文件将swift导入到Objective-c类中,但是预处理器无法找到生成的头文件并在导入中抛出错误。

"Lexical or Preprocessor issue : 'ModuleName-Swift.h file not found'"

词汇或预处理问题:“模块-快速。”h文件未找到”

Xcode 8与混合Swift和Objective-c项目生成“模块化-Swift”。h”头未找到

The project compiles just fine, but the preprocessor throws errors for the header not being found and for any Swift classes called inside the class there is no syntax highlighting or code completion. It's a struggle working with Swift classes in Objective-c that are unrecognized by Xcode 8, but yet compile just fine.

这个项目编译得很好,但是预处理程序会为未被发现的头抛出错误,并且在类中调用的任何Swift类都没有语法突出显示或代码完成。在Objective-c中使用Swift类是一件很困难的事情,Xcode 8无法识别这些类,但是编译很好。

Any ideas on how to appease the preprocessor in Xcode 8?

对如何满足Xcode 8中的预处理器有什么想法吗?

5 个解决方案

#1


23  

I had exactly the same issue. Found the solution after adding a new file aiming to only one target (by mistake) and noticing that it had no problem reading the Swift classes. So, if you have multiple targets, and since the migration you didn't have the need to build and run them, suggest you to do that.

我也有同样的问题。在只针对一个目标(错误地)添加一个新文件并注意到阅读Swift类没有问题之后,找到了解决方案。因此,如果您有多个目标,并且由于迁移您不需要构建和运行它们,建议您这样做。

#2


4  

Have this problem when we have multiple targets. If the Objective-c Generated Interface Header Name variable in Swift compiler of newly created targets is different than the original target's value. Change it to the same value with original target. See the following:

当我们有多个目标时就会有这个问题。如果新创建目标的Swift编译器中由Objective-c生成的接口头名变量与原始目标的值不同。将其更改为与原来的目标相同的值。见以下:

change, newtargetname-Swift.h to originaltargetname-Swift.h for new target

改变,newtargetname-Swift。originaltargetname-Swift h。h为新目标

Xcode 8与混合Swift和Objective-c项目生成“模块化-Swift”。h”头未找到

#3


1  

You need to add this in your build settings.

您需要在构建设置中添加这个。

There might be an issue while migrating to Xcode 8, where you will have unspecified in the build setting Swift header file.

在迁移到Xcode 8时可能会有问题,您将在构建设置Swift头文件中有未指定的内容。

This if from killerz

如果从killerz

Go to Build Settings->Objective-C Generated Interface Header Name and set the value to YourModule-Swift.h (this is usually already set, this is the filename you need to import on .m file #import "YourModule-Swift.h"

转到Build Settings—>Objective-C生成的接口头名,并将值设置为yourmodul - swift。h(这通常已经设置好了,这是您需要在.m文件#import“YourModule-Swift.h”中导入的文件名。

#4


1  

If

如果

  • your product's normal targets run fine, but
  • 你的产品的正常目标运行良好,但是。
  • you get the error when running your test targets…
  • 在运行测试目标时,您会得到错误…

note that each target uses (and should use) a different filename for the Objective-C Generated Interface Header Name.

注意,每个目标都使用(并且应该使用)不同的文件名作为Objective-C生成的接口头名。

This means you cannot import the generated header file in your Objective-C .h files, because they won't be found in the test target:

这意味着您不能在您的Objective-C .h文件中导入生成的头文件,因为它们不会在测试目标中找到:

Xcode 8与混合Swift和Objective-c项目生成“模块化-Swift”。h”头未找到

Instead, you should move these #import statements into your Objective-C .m (implementation files), where they'll build successfully.

相反,您应该将这些#import语句移动到您的Objective-C .m(实现文件)中,它们将在那里成功构建。


If you need to refer to Swift classes in a .h file, use the @class directive, e.g.:

如果需要在.h文件中引用Swift类,请使用@class指令,例如:

//
//  ViewController.h
//  import-example
//

#import <UIKit/UIKit.h>

@class SomeSwiftClass;

@interface ViewController : UIViewController

- (NSString *) titleFromGenerator:(SomeSwiftClass *)generator;

@end

#5


0  

To fix this issue Xcode 9.2, After long research i came to known my "Objective-c Generated Interface Header Name" is named after Product Name "productname-Swift.h"Xcode 8与混合Swift和Objective-c项目生成“模块化-Swift”。h”头未找到

为了解决这个问题Xcode 9.2,经过长时间的研究,我知道我的“Objective-c生成的接口头名”是以产品名“productname-Swift.h”命名的

#1


23  

I had exactly the same issue. Found the solution after adding a new file aiming to only one target (by mistake) and noticing that it had no problem reading the Swift classes. So, if you have multiple targets, and since the migration you didn't have the need to build and run them, suggest you to do that.

我也有同样的问题。在只针对一个目标(错误地)添加一个新文件并注意到阅读Swift类没有问题之后,找到了解决方案。因此,如果您有多个目标,并且由于迁移您不需要构建和运行它们,建议您这样做。

#2


4  

Have this problem when we have multiple targets. If the Objective-c Generated Interface Header Name variable in Swift compiler of newly created targets is different than the original target's value. Change it to the same value with original target. See the following:

当我们有多个目标时就会有这个问题。如果新创建目标的Swift编译器中由Objective-c生成的接口头名变量与原始目标的值不同。将其更改为与原来的目标相同的值。见以下:

change, newtargetname-Swift.h to originaltargetname-Swift.h for new target

改变,newtargetname-Swift。originaltargetname-Swift h。h为新目标

Xcode 8与混合Swift和Objective-c项目生成“模块化-Swift”。h”头未找到

#3


1  

You need to add this in your build settings.

您需要在构建设置中添加这个。

There might be an issue while migrating to Xcode 8, where you will have unspecified in the build setting Swift header file.

在迁移到Xcode 8时可能会有问题,您将在构建设置Swift头文件中有未指定的内容。

This if from killerz

如果从killerz

Go to Build Settings->Objective-C Generated Interface Header Name and set the value to YourModule-Swift.h (this is usually already set, this is the filename you need to import on .m file #import "YourModule-Swift.h"

转到Build Settings—>Objective-C生成的接口头名,并将值设置为yourmodul - swift。h(这通常已经设置好了,这是您需要在.m文件#import“YourModule-Swift.h”中导入的文件名。

#4


1  

If

如果

  • your product's normal targets run fine, but
  • 你的产品的正常目标运行良好,但是。
  • you get the error when running your test targets…
  • 在运行测试目标时,您会得到错误…

note that each target uses (and should use) a different filename for the Objective-C Generated Interface Header Name.

注意,每个目标都使用(并且应该使用)不同的文件名作为Objective-C生成的接口头名。

This means you cannot import the generated header file in your Objective-C .h files, because they won't be found in the test target:

这意味着您不能在您的Objective-C .h文件中导入生成的头文件,因为它们不会在测试目标中找到:

Xcode 8与混合Swift和Objective-c项目生成“模块化-Swift”。h”头未找到

Instead, you should move these #import statements into your Objective-C .m (implementation files), where they'll build successfully.

相反,您应该将这些#import语句移动到您的Objective-C .m(实现文件)中,它们将在那里成功构建。


If you need to refer to Swift classes in a .h file, use the @class directive, e.g.:

如果需要在.h文件中引用Swift类,请使用@class指令,例如:

//
//  ViewController.h
//  import-example
//

#import <UIKit/UIKit.h>

@class SomeSwiftClass;

@interface ViewController : UIViewController

- (NSString *) titleFromGenerator:(SomeSwiftClass *)generator;

@end

#5


0  

To fix this issue Xcode 9.2, After long research i came to known my "Objective-c Generated Interface Header Name" is named after Product Name "productname-Swift.h"Xcode 8与混合Swift和Objective-c项目生成“模块化-Swift”。h”头未找到

为了解决这个问题Xcode 9.2,经过长时间的研究,我知道我的“Objective-c生成的接口头名”是以产品名“productname-Swift.h”命名的