1

I have installed Card.IO via CocoaPods. My workspace looks to be correctly setup, I see the Card.IO Objective-C header files in place however when, in my main Swift project, I try to reference any of the Card.IO classes - I get the unresolved identifier error.

Edit My understanding is that Xcode cannot find the bridging header:

#import "CardIO.h"

@import AudioToolbox;
@import AVFoundation;
@import CoreMedia;
@import CoreVideo;
@import MobileCoreServices;

The documentation states

In Build Settings, in Swift Compiler - Code Generation, make sure the Objective-C Bridging Header build setting under has a path to the bridging header file. The path should be relative to your project, similar to the way your Info.plist path is specified in Build Settings. In most cases, you should not need to modify this setting.

This doesn't make sense to me - so not sure where to put the path? I've added the following to Build Settings > Search Paths > Header Search Paths > Debug & Release

MyApp/MyApp-Bridging-Header.h

but it seems this is incorrect?

clicky
  • 865
  • 2
  • 14
  • 31
  • Have you added .h files in bridging header? – Saqib Omer Nov 23 '15 at 08:43
  • I have copied the contents of their bridging header into a .h file. This only has imports of frameworks and doesn't resolve the issue. Also the steps on GitHub page just say to install via cocoa pods - no other steps needed. – clicky Nov 23 '15 at 09:49
  • 1
    1: CocoaPods are different than normal xCode projects. (go through readme file of card-io) 2: You need to create your own bridging header and import .h files as in sample SampleApp-Swift. (Dont copy entire bridging-header file in your project. ) – Saqib Omer Nov 23 '15 at 09:53
  • I have updated the question with the bridging header I added - still doesn't resolve – clicky Nov 23 '15 at 12:26
  • @SaqibOmer not always ;) just use use_frameworks! – Daij-Djan Nov 23 '15 at 12:55
  • @clicky do what @Daij-Djan says and add `use_frameworks!` to your `Podfile`, re-install, then you can use import statements `(FYI import NOT @import)` instead of using a bridging header file. – sbarow Nov 23 '15 at 12:57
  • @sbarow I already have this in my Podfile... – clicky Nov 23 '15 at 12:59
  • @clicky build your project and see if the errors go away, sometimes before you build you will see errors when trying to import. – sbarow Nov 23 '15 at 13:02
  • @sbarow no difference after building – clicky Nov 23 '15 at 13:08
  • if you have it in the pod, then don't add a bridging header and just import it – Daij-Djan Nov 23 '15 at 13:32
  • @Daij-Djan `import CardIO` does not work – clicky Nov 23 '15 at 13:43

1 Answers1

1

Found the answer here

https://bohemianpolymorph.wordpress.com/2014/07/11/manually-adding-a-swift-bridging-header/

In your project build settings, find Swift Compiler – Code Generation, and next to Objective-C Bridging Header add the path to your bridging header file, from the project’s root folder. So it could by MyProject/MyProject-Bridging-Header.h or simply MyProject-Bridging-Header.h if the file lives in the project root folder.

clicky
  • 865
  • 2
  • 14
  • 31