Could not build Objective-C module 'mupdfdk' - ios

I'm trying to add mupdf framework to a swift project. I created a new project and copied the mupdfdk.framework to my project and referenced it in the frameworks section. Following is a screenshot of the documentation.
Now my project looks like this.
Then when I try to import it in viewcontroller, I get Could not build Objective-C module 'mupdfdk' error. Are there any other steps I'm missing? Please help.

You need to add this bridging header:
MuPDF-Bridging-Header.h
#ifndef MuPDF_Bridging_Header_h
#define MuPDF_Bridging_Header_h
#import "mupdfdk.framework/Headers/mupdfdk.h"
#endif /* MuPDF_Bridging_Header_h */
and declare it within the Swift Compiler section of the Build Settings:

Related

'FMDB.h' file not found

have been trying to import a header file for database.
I'm getting two errors.
'FMDB.h' file not found
and
ailed to emit precompiled header '/Users/myname/Library/Developer/Xcode/DerivedData/zzzzzz- for bridging header '/Users/myname/Library/Autosave Information/zzzzzz/header.h'
The full path of FMDB.h is the below
/Users/myname/Library/Autosave Information/zzzzzz/fmdb/FMDB.h
In Objective-C Bridging Header : header.h
in the header file, the codes are :
#ifndef Header_h
#define Header_h
#import "FMDB.h"
#endif /* Header_h */
I set Allow Non-modular Includes in Framework Modules as Yes.
It didn't work out for me tho.
Follow a few steps:
Rename your header to --> YourProjectName-Bridging-Header.h
Check/Add Path of this header in your Build Setting --> Under Objective-CBridging Header (You may drag the file path)
Framework Modules as No
Then build, it should work. thanks!
I recently moved to new Mac book with Apple M1 Max chip and got the same error. I resolved it by removing arm64 from EXCLUDED_ARCHS in Build Settings.

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?
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
I had similar issue and almost ended up spending a whole day trying to figure out what wrong with my app.
So following the solution that's helped me :
Clear derived data
Create a class in swift with prefix of #objc for example #objc class mySwiftClass{...}
Build the project again
Et voila.. Should work now.
Why to add #objc?
this #objc prefix, tells the compiler to generate to your swift class a header file. it will add it to the "MyModule-Swift.h" file
I realize this is an old thread, but I had similar issues after adding a new target to a project. I solved it by adding a preprocessor macro (Build Settings -> Apple Clang - Preprocessing) only in said target and then importing the Swift.h file conditionally, like this:
#if DEV_VERSION
#import "Project_DEV-Swift.h"
#else
#import "Project-Swift.h"
#endif
My main target is called Project and the new target is Project DEV (the space is replaced with an underscore in the import), and the preprocessor macro is called DEV_VERSION.
After doing this, both targets build just fine.
<product_name>-Swift.h file not found
It is a kind of bridge(adapter) between Swift and Objective-C. This file contains Swift's API for Objective-C which was marked [#objc and #objcMembers].
You can work with types declared in Swift from within the Objective-C code in your project by importing an Xcode-generated header file.
The header's name is generated from a <product_name>-Swift.h
[Mixing Objective-C and Swift ]
I had a similar issue whereby it would have this issue for anything other than live.
I resolved the issue by hardcoding "Product module name" & "Product name" to my project name. This avoids the need to have preprocessor logic in every file that includes swift code as demonstrated in Pauli Kettunen's solution.

iOS Swift project, have Objective-C file and I want to import a swift class to the Objective-C file [duplicate]

I have written a library in Swift and I wasn't able to import it to my current project, written in Objective-C.
Are there any ways to import it?
#import "SCLAlertView.swift" - 'SCLAlertView.swift' file not found
You need to import ProductName-Swift.h. Note that it's the product name - the other answers make the mistake of using the class name.
This single file is an autogenerated header that defines Objective-C interfaces for all Swift classes in your project that are either annotated with #objc or inherit from NSObject.
Considerations:
If your product name contains spaces, replace them with underscores (e.g. My Project becomes My_Project-Swift.h)
If your target is a framework, you need to import <ProductName/ProductName-Swift.h>
Make sure your Swift file is member of the target
Here's what to do:
Create a new Project in Objective-C
Create a new .swift file
 
A popup window will appear and ask "Would You like to configure an Objective-C bridging Header".
Choose Yes.
Click on your Xcode Project file
Click on Build Settings
Find the Search bar and search for Defines Module.
Change value to Yes.
Search Product Module Name.
Change the value to the name of your project.
In App delegate, add the following : #import "YourProjectName-Swift.h"
Note: Whenever you want to use your Swift file you must be import following line :
#import "YourProjectName-Swift.h"
Instructions from the Apple website:
To import Swift code into Objective-C from the same framework
Under Build Settings, in Packaging, make sure the Defines Module
setting for that framework target is set to Yes. Import the Swift code
from that framework target into any Objective-C .m file within that
framework target using this syntax and substituting the appropriate
names:
#import "ProductName-Swift.h"
Revision:
You can only import "ProductName-Swift.h" in .m files.
The Swift files in your target will be visible in Objective-C .m files
containing this import statement.
To avoid cyclical references, don’t import Swift into an Objective-C
header file. Instead, you can forward declare a Swift class to use it
in an Objective-C header. Note that you cannot subclass a Swift class
in Objective-C.
If you're using Cocoapods and trying to use a Swift pod in an ObjC project you can simply do the following:
#import <FrameworkName>;
Go to build settings in your project file and search for "Objective-C Generated Interface Header Name. The value of that property is the name that you should include.
If your "Product Module Name" property (the one that the above property depends on by default) varies depending on whether you compile for test/debug/release/etc (like it does in my case), then make this property independent of that variation by setting a custom name.
Importing Swift file inside Objective-c can cause this error, if it doesn't import properly.
NOTE: You don't have to import Swift files externally, you just have to import one file which takes care of swift files.
When you Created/Copied Swift file inside Objective-C project. It would've created a bridging header automatically.
Check Objective-C Generated Interface Header Name at Targets -> Build Settings.
Based on above, I will import KJExpandable-Swift.h as it is.
Your's will be TargetName-Swift.h, Where TargetName differs based on your project name or another target your might have added and running on it.
As below my target is KJExpandable, so it's KJExpandable-Swift.h
First Step:-
Select Project Target -> Build Setting -> Search('Define') -> Define Module
update value No to Yes
"Defines Module": YES.
"Always Embed Swift Standard Libraries" : YES.
"Install Objective-C Compatibility Header" : YES.
Second Step:-
Add Swift file Class in Objective C ".h" File as below
#import <UIKit/UIKit.h>
#class TestViewController(Swift File);
#interface TestViewController(Objective C File) : UIViewController
#end
Import 'ProjectName(Your Project Name)-Swift.h' in Objective C ".m" file
//TestViewController.m
#import "TestViewController.h"
/*import ProjectName-Swift.h file to access Swift file here*/
#import "ProjectName-Swift.h"
If you have a project created in Swift 4 and then added Objective-C files, do it like this:
#objcMembers
public class MyModel: NSObject {
var someFlag = false
func doSomething() {
print("doing something")
}
}
Reference: https://useyourloaf.com/blog/objc-warnings-upgrading-to-swift-4/
There's one caveat if you're importing Swift code into your Objective-C files within the same framework. You have to do it with specifying the framework name and angle brackets:
#import <MyFramework/MyFramework-Swift.h>
MyFramework here is the "Product Module Name" build setting (PRODUCT_NAME = MyFramework).
Simply adding #import "MyFramework-Swift.h" won't work. If you check the built products directory (before such an #import is added, so you've had at least one successful build with some Swift code in the target), then you should still see the file MyFramework-Swift.h in the Headers directory.
Be careful with dashes and underscores, they can be mixed up and your Project Name and Target name won't be the same as SWIFT_MODULE_NAME.
Checkout the pre-release notes about Swift and Objective C in the same project
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_75
You should be importing
#import "SCLAlertView-Swift.h"
Search for "Objective-C Generated Interface Header Name" in the Build Settings of the target you're trying to build (let's say it's MyApp-Swift.h), and import the value of this setting (#import "MyApp-Swift.h") in the source file where you're trying to access your Swift APIs.
The default value for this field is $(SWIFT_MODULE_NAME)-Swift.h. You can see it if you double-click in the value field of the "Objective-C Generated Interface Header Name" setting.
Also, if you have dashes in your module name (let's say it's My-App), then in the $(SWIFT_MODULE_NAME) all dashes will be replaced with underscores. So then you'll have to add #import "My_App-Swift.h".
If you want to use Swift file into Objective-C class, so from Xcode 8 onwards you can follow below steps:
If you have created the project in Objective-C:
Create new Swift file
Xcode will automatically prompt for Bridge-Header file
Generate it
Import "ProjectName-Swift.h" in your Objective-C controller (import in implementation not in interface) (if your project has space in between name so use underscore "Project_Name-Swift.h")
You will be able to access your Objective-C class in Swift.
Compile it and if it will generate linker error like: compiled with newer version of Swift language (3.0) than previous files (2.0) for architecture x86_64 or armv 7
Make one more change in your
Xcode -> Project -> Target -> Build Settings -> Use Legacy Swift Language Version -> Yes
Build and Run.
#import <TargetName-Swift.h>
you will see when you enter from keyboard #import < and after automaticly Xcode will advice to you.
only some tips about syntax, about Xcode everything has been said
you cannot import 'pure" functions, only classes, even if marked "public", so:
public func f1(){
print("f1");
}
will NOT be called in ANY way.
If You write classes., add inheritance from NSObject, other will NOT be usable.
if it inherits from NSObject, as below:
class Utils : NSObject{
static func aaa()->String{
return "AAA"
}
#objc static func bbb()->String{
return "BBB"
}
#objc private static func ccc()->String{
return "CCC"
}
}
in OBJC:
aaa() NOT called: "No known class method for selector 'aaa'"
bbb() ok
ccc() NOT called: "No known class method for selector 'aaa'"
Find the .PCH file inside the project. and then add #import "YourProjectName-Swift.h" This will import the class headers. So that you don't have to import into specific file.
#ifndef __IPHONE_3_0
#warning "This project uses features only available in iPhone SDK 3.0 and later."
#endif
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "YourProjectName-Swift.h"
#endif

Use of undeclared type 'RoboViewController' Swift

I install RoboReaderPDF framework via pod in my project and I imported it in my Bridging-Header.h file
the issue is when I am trying to instantiate the RoboViewController I am getting this error
Use of undeclared type 'RoboViewController'
any help!?
Looks like your bridging header has not been set up correctly. It should have the following structure.
#ifndef Bridging_Header_h
#define Bridging_Header_h
#import <RoboReaderPDF/RoboReader.h>
#endif
Importing the RoboReader.h file will also import the view controller (check file contents).
Additionally, also check that your bridging header has been specified under Objective-C Bridging Header key in Swift Compiler - Code Generation segment in Build settings.

Xcode "Missing Submodule" warning

I'm using Xcode6 GM to create a Coacoa Touch Framework (a new function in Xcode6), then this framework is included into my app.
Everything is fine (works fine), except that I get warnings in "#import". What is the root cause?
I ran into the same problem and eventually fixed it by adding my project headers into the umbrella header. When you create a new framework it should start with a single .h file titled by the project (in your case DirectProximityFramework.h).
Inside this file is a comment:
In this header, you should import all the public headers of your
framework using statements like #import <DirectProximityFramework/PublicHeader.h>
So just add your GeofencingHelper.h file in this file:
#import <DirectProximityFramework/GeofencingHelper.h>
This should remove all of your warnings!
Maybe, you can stop this warning by adding following line to "DirectProximityFramework.h"
#import <DirectProximityFramework/GeofencingHelper.h>
...etc
I suggest to check
[Target your framework] -> Build Phases -> Headers -> Public
In case if it is not your framework and there is nothing to do you can disable warning in such way
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wincomplete-umbrella"
#import <DirectProximityFramework/GeofencingHelper.h>
#pragma clang diagnostic pop
Note - it is not a fix, it just hide the problem.
I ran into this issue and all the solutions above didn't fit me, since the file wasn't supposed to be in the umbrella header.
So if this is your own framework and that particular file shouldn't be in the umbrella header, make sure it isn't marked public in the target membership section.
That fixed it for me.
I had same issue and my solution was..
When you create the framework project.Your project automatically "yourProjectName.h" file gets created, In this header file import class class.
In my case I am getting missing submodule 'MSFramework.MSLocationManager' [-Wincomplete-umbrella]this warning.
resolved by Just importing
#import <UIKit/UIKit.h>
# import "MSLocationManager.h"
//! Project version number for MSFramework.
FOUNDATION_EXPORT double MSFrameworkVersionNumber;
//! Project version string for MSFramework.
FOUNDATION_EXPORT const unsigned char MSFrameworkVersionString[];
here I just add the # import "MSLocationManager.h"in header file.
// In this header, you should import all the public headers of your framework using statements like
#import <GameworkSDK/GWObject.h>
like this:
#import <UIKit/UIKit.h>
#import <GameworkSDK/GWObject.h>
//! Project version number for GameworkSDK.
FOUNDATION_EXPORT double GameworkSDKVersionNumber;
//! Project version string for GameworkSDK.
FOUNDATION_EXPORT const unsigned char GameworkSDKVersionString[];
i had this problem cocoa pods
my solution was real simple but took forever for me to figure out.
when i ran $ pod install it generated a workspace for me in the same dir as my .xcodeproj file.
however i had already created a workspace to use as its parent directory.
so then i simply deleted my old workspace and went with the one that pods created
glhf!
Set header search path in your project setting:
TARGETS / Build Settings / Header Search Paths
"$PODS_CONFIGURATION_BUILD_DIR/[YOUR PROJ NAME]/[YOUR PROJ NAME].framework/Headers"
Now import the header file.
#import <DirectProximityFramework.h>

Resources