11

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

Community
  • 1
  • 1
Rohan Sanap
  • 2,773
  • 2
  • 21
  • 39
  • 1
    http://stackoverflow.com/questions/31099596/importing-swift-framework-into-a-objective-c-project check this question out, you may find a answer here – satheesh Nov 26 '15 at 06:07
  • @JoshCaswell My edit clearly specifies why my question is not same as the one specified as duplicate. Please remove the duplicate mark if you find my edit convincing, so that I get solutions soon. – Rohan Sanap Nov 26 '15 at 06:24
  • @satheesh I am also not able to do `@import Charts` – Rohan Sanap Nov 26 '15 at 06:29
  • See also [How to import and use Swift pod framework in ObjC project?](http://stackoverflow.com/q/27995691) – jscs Nov 26 '15 at 06:31
  • @JoshCaswell Let me give you steps to replicate my problem. 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 `@impot Charts` but it gives error at this point. – Rohan Sanap Nov 26 '15 at 06:39
  • @JoshCaswell done! at least now you might have realized that my question is not a duplicate! Please remove the duplicate mark. – Rohan Sanap Nov 26 '15 at 08:28
  • Are you building your project from xcodeproject or xcworkspace file after installing pod? – Anni S Nov 26 '15 at 08:47
  • xcworkspace file @Anni S – Rohan Sanap Nov 26 '15 at 09:49

3 Answers3

10

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.

Community
  • 1
  • 1
Rohan Sanap
  • 2,773
  • 2
  • 21
  • 39
7

I tried the same step what you mentioned in the comment however I was not getting the error that you got. My project simply builds and runs. Steps that I followed:

  1. Create Objective-C single view project.
  2. Added 'Podfile' in the project directory level (Podfile should be at the xcodeproject file level) and add following lines
use_frameworks!
pod 'Charts'
  1. Close xcodeproject
  2. Go to project directory and run the 'pod install' command from the termial
  3. Open workspace i.e. .xcworkspace file
  4. Import charts file in view controller such as

#import "ViewController.h" @import Charts;

Anni S
  • 1,996
  • 19
  • 28
  • This worked when I tried your steps with new project but not with my existing project. – Rohan Sanap Nov 26 '15 at 11:24
  • So I guess, you might be missing something in existing project. Just delete all the cocoaPod related files in your existing project and try again the steps mentioned in the answer. – Anni S Nov 26 '15 at 11:31
0

I found the reason why it works for new project, but for an existing project.

In the project settings, delete the value of the Other Linker Flags property.

This is the most case that most developers are being missed.

Harri Westman
  • 140
  • 1
  • 7