Xcode 8 with Mixed Swift and Objective-C Project Generated "Modulename-Swift.H" Header Not Found

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

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.

ModuleName-Swift.h file not found in xcode8

The assumption I made in Edit 4 turned out to be the correct one.
If a project has multiple targets the "-Swift.h" files cannot be imported all in one .m ObjectiveC file.

So there is one solution that must be adopted and it is to change the SWIFT_OBJC_INTERFACE_HEADER_NAME build setting and making it the same across different targets.
To do so change the instruction that generates this property from $(SWIFT_MODULE_NAME)-Swift.h to $(PROJECT_NAME)-Swift.h as explained here

It is also possible to set the Product Module Name setting in Build Settings to be the same across your modules (I set it to $(PROJECT_NAME)), so that the -Swift.h file that is generated has the same name across all modules. This eliminates the need for adding/checking preprocessor macros.

After doing this Clean Build Folder by pressing Alt and going into Product menu. Since name of header is shared among targets now it can be imported once in the .m ObjectiveC file and all targets can benefit from Swift classes.

If after building it still shows the error, ensure that the header can be reached from XCode by Cmd clicking on its name. It should open a file that contains code similar to this:

SWIFT_CLASS("_TtC27ProjectName_Summary11MyClass")
@interface MyClass : NSObject
- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end

If need to ensure that those headers are being generated open a terminal and use this command

find ~/Library/Developer/Xcode/DerivedData -name "*Swift.h"

You should see one header for each target

Another issue that happened to me after those changes is that it started giving errors on ObjectiveC code that I didn't touch. The problem was due to the position of the import, as reported here:

Exactly where at the top of a .m file you #import the hidden bridging header can make a difference. The usual sign of trouble is that you get an “Unknown type name” compile error, where the unknown type is a class declared in Objective-C. The solution is to #import the .h file containing the declaration for the unknown type in your Objective-C files as well, before you #import the hidden bridging header. Having to do this can be an annoyance, especially if the Objective-C file in question has no need to know about this class, but it resolves the issue and allows compilation to proceed.

At the very end the code compiles and runs on device and simulator!

Xcode Pods functions not found in ModuleName-Swift.h

Thanks to Kavitha Madhu, I found the solution !

For those who encounter the same issue:

If you want to use Swift classes and functions in you Objective-C code.

But, some of you Swift functions use Pods protocols and delegates.

You need to add in your Objective-C code the import of the pods headers that contain these protocols and delegates.

For example, if your module-Swift.h doesn't find "SlideNavigationControllerDelegate", you need to add in the Objective-C file (which use "module-Swift.h") the line:

#import <iOS_Slide_Menu/SlideNavigationController.h>

Importing Project-Swift.h into a Objective-C class...file not found

I was running into the same issue and couldn't get my project to import swift into obj-c classes. Using Xcode 6, (should work for Xcode 6+) and was able to do it in this way....

  1. Any class that you need to access in the .h file needs to be a forward declaration like this

@class MySwiftClass;


  1. In the .m file ONLY, if the code is in the same project (module) then you need to import it with

#import "ProductModuleName-Swift.h"

Link to the apple documentation about it

https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_swift_into_objective-c

mymodule-swift.h file not found

I was facing this same issue Xcode 8 with mixed Swift and Objective-c project generated "ModuleName-Swift.h" header not found

I solved just building every target with the conflicted objective-c file closed.

After that, everything is working properly again.

Project-Swift.h file not found

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

Importing modulename-Swift.h file to ObjC .h file

No, you can't import modulename-Swift.h in a .h file. You'll need to create forward declarations (adding @protocol Something; to your .h) and import the Swift module in the .m file.

Another way to work around this is to declare the protocol conformance in a category in the .m file. More details can be found in this StackOverflow answer:

https://stackoverflow.com/a/27626493/3208043

Module not found inside 'Framework' -Swift.h file

First, update bundle identifiers of your targets SampleFramework, SampleSwift, SampleObjc to be different.

Try updating Podfile as follows. Cocoapods works this way that in your setup you have to specify 'Google-Mobile-Ads-SDK' for every target which uses it, but to avoid copying that line, you can use abstract_target so the dependency is automatically added to all targets inside:

use_frameworks!

abstract_target 'Common' do
pod 'Google-Mobile-Ads-SDK'

target 'SampleFramework' do
end

target 'SampleObjc' do
end

target 'SampleSwift' do
end
end

But this way you will face a runtime warning "Class APMAdExposureReporter is implemented in both ...", but the app will work, the warning doesn't cause real problems - it's discussed here, but personally I don't know the best practice how to deal with it.



Related Topics



Leave a reply



Submit