1

It has cost me a lot of hours. Want to know if others have been confronted with the same issue.

I am developing this Swift/ObjC Hybrid project which is using GoogleMap iOS SDK. Note that I am using Cocoa Pod to manage the library reference. (I don't know whether it would cost any issue).

So I have checked the standard Apple document on "Mix and Match" which give all the standard steps to cross reference between Objc and Swift.

I have checked this popular StackOverFlow thread for troubleshooting the potential issues.

I have created a very simple ObjC project and successfully referenced the Swift Class into my Objective C based ViewController.

BUT!!! I am not able to do it in the project I am actively working with. Here are the screenshot of the project. If anyone knows anything please help me. Thanks. enter image description here

enter image description here

enter image description here

I don't know how but the Swift Class is not referenced in the Bridging Header.....

Community
  • 1
  • 1
TypingPanda
  • 1,607
  • 3
  • 19
  • 32
  • This means that something in your Swift class cannot translate to Objective-C. From first glance I don't see anything that stands out at me. I don't believe the `@objc` tag is required on the class or the funcs for this. Try making the `let apiKey = ...` and `session` variables that instantiate in an `init`. Just guesses at Swift declarations that may not translate to Objective-C. See [this](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_86) for things you can and cannot use in your Swift class. – keithbhunter Sep 25 '15 at 14:45
  • Thanks for your attempted Answer Keith. Actually I found out the problem with my X-code version is that you have to have the Objective-C Bridging Header Ready. Otherwise the code won't work. – TypingPanda Sep 27 '15 at 14:03

1 Answers1

0

After a very deep detailed comparison of the project settings I found out that you have to have the Objective-C bridging header ready.

On creation of the Swift Class, I selected not to automatically creating the ObjectiveC Bridging Header which sit at the core of the problem.

enter image description here

Like show in the picture, creating a header file with name "[Project module name]-Bridging-Header.h" and put the correct path of the file in the "Build Settings" for "Objective-C Bridging Header" item.

Build the project and Voilà~~~ Your swift class is now visible in your objective C code.

Kevin ABRIOUX
  • 16,507
  • 12
  • 93
  • 99
TypingPanda
  • 1,607
  • 3
  • 19
  • 32