Xcode 8 with mixed Swift and Objective-c project generated “ModuleName-Swift.h” header not found

后端 未结 5 1555
醉话见心
醉话见心 2020-12-08 07:36

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 pre

相关标签:
5条回答
  • 2020-12-08 08:10

    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.

    0 讨论(0)
  • 2020-12-08 08:16

    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:

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

    0 讨论(0)
  • 2020-12-08 08:25

    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.

    This if from 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"

    0 讨论(0)
  • 2020-12-08 08:27

    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"

    0 讨论(0)
  • 2020-12-08 08:35

    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.

    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:

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


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

    //
    //  ViewController.h
    //  import-example
    //
    
    #import <UIKit/UIKit.h>
    
    @class SomeSwiftClass;
    
    @interface ViewController : UIViewController
    
    - (NSString *) titleFromGenerator:(SomeSwiftClass *)generator;
    
    @end
    
    0 讨论(0)
提交回复
热议问题