9

I am working in an Objective-C, iOS project, I used danielgindi Charts library which is a Swift library. I downloaded it using Cocoapods.

I am trying to import the library files into my Objective-C files using 'projectName-Swift.h' as mentioned in this question but I faced an error:

'projectName-Swift.h' file not found

Community
  • 1
  • 1
Ahd Radwan
  • 1,090
  • 4
  • 14
  • 31
  • Did you checked usage section of Charts lib? When using Swift in an ObjC project: You need to import your Bridging Header. Usually it is "YourProject-Swift.h", so in ChartsDemo it's "ChartsDemo-Swift.h". Do not try to actually include "ChartsDemo-Swift.h" in your project :-) Under "Build Options", mark "Embedded Content Contains Swift Code" – David V May 28 '16 at 19:54
  • @DavidV I noticed this and imported 'myprojectName-Swift.h' and I set "Embedded Content Contains Swift Code" to yes. I faced the same issue – Ahd Radwan May 28 '16 at 20:27

3 Answers3

10

If you have installed Swift library using cocoapods

To import Library in Objective C Code Use in Objective C

@import frameworkname;

In Swift

@import frameworkname
1

If your using cocoa pods try to make sure you have use_frameworks! in your cocoa pods pod file, otherwise the Swift Framework wont work. Also look at this for any other issues that may pop up: link

GlorySaber
  • 367
  • 2
  • 12
  • 2
    The swift framework has to explicitly support Objective C as is mentioned here http://stackoverflow.com/questions/31099596/importing-swift-framework-into-a-objective-c-project Could this be your problem? – GlorySaber May 28 '16 at 20:42
1

For making the bridging header visible to your compiler you need a little setup

  1. Go to your Project Build Settings
  2. Search for bridging header
  3. Add the path to your .h file (usually ProjectName/ProjectName-Swift.h)