Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found error when importing Swift pod into Objective-C project

I have an existing project which is written in Objective-C. I want to use the iOS Charts library by Daniel Gindi, which is in Swift, in that project. How can I achieve this?

importing swift framework into a objective-c project is related, but in my case I am using the library by installing it through Cocoapods as instructed here.

In that question, he is at least able to import the header, but in my case I am not able to.

step 1: Create Objective-C single view project.

step 2: Create a Podfile and add following lines -

use_frameworks!
pod 'Charts'

step 3: Install the pod

step 4: Try to import Charts in ViewController.h by @import Charts but it gives an error at this point. The error is - Module Charts not found

like image 607
Rohan Sanap Avatar asked Nov 26 '15 05:11

Rohan Sanap


People also ask

How do I import a Swift file into Objective-C?

Import Swift code into Objective-C within 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 .

Is Objective-C compatible with Swift?

You can use Objective-C and Swift files together in a single project, no matter which language the project used originally. This makes creating mixed-language app and framework targets as straightforward as creating an app or framework target written in a single language.

How do you use Swift Cocoapods in Objective-C?

Support Objective-C pods in a Swift project First, create your Podfile and add the pods you need as usual. Install them using the pod install command and open the . xcworkspace file created in your project folder. Pods should now be included in your workspace.

What is Swift H?

${Your project name}-Swift. h is for objc based project to use swift code I remember. It is generated by XCode, to translate swift code to a header file for objc to import. If you don't need to use swift in objc project, you don't need it.


1 Answers

In my existing project, I did #include Charts-Swift.h in my project's main.m file and this solved problem from me. @import Charts worked perfectly now. This was done according to the instructions that are written in Apple documentation here.

I made a new project and tried Anni S's answer, this time I built the project with cmd+B before writing any import statement and it worked too. I guess building it once after installing pod and before importing any module is necessary.

like image 187
Rohan Sanap Avatar answered Sep 23 '22 11:09

Rohan Sanap