Swift Bridging Header and visibility of Obj-C class
Asked Answered
N

2

7

I've aded bridging header, specified in build settings the full path to it, bridging header was created automatically. After this, i've included my obj-c header files in it. But every attempt of calling constructor of object fails : "Use of undeclared identifier". enter image description here

The list of things i've done :

  1. Created .m file and Xcode proposed to create bridging header
  2. Added obj-c files to project and imported them in header
  3. In build setting provided the FULL path to bridging header file

enter image description here

  1. Used Obj-C type in code... But it doesn't builds.
  2. Then, i provided not the full path to the header, but the path from the folder in which project is - no result.

I double-checked all the steps according to apple documentation, but no result. Why? Any help would be appreciated.

Nod answered 28/6, 2014 at 15:54 Comment(5)
What error do you get though? After adding your Obj-C class header to the bridging-header you should be able to just init an Obj-C object and then use its methods like normal. You shouldn't need to use the full paths in the build settings as the relative ones should work fine. I would bet that somewhere in there you have a path error.Manure
Posting code would help us.Trowbridge
Try run Terminal, run cat "YOUR_BRIDGING_HEADER_PATH", does that print anything? Also why don't you try create a fresh test project, do all the steps start over, see what's missing?Trowbridge
Yep, it contains import "Bl_KeyChainNativeWrapper.h"Nod
Anyone knows answer to this: #30522668 ?Scarabaeus
T
2

Follow these steps:

  1. Create a Swift project
  2. Add a test class as Cocoa Class instead of .m and .h separately. Xcode prompt add bridging header.
  3. Import test class header in bridging header, which you already did. Should have no issue instantiate test class in Swift.
  4. Copy BL_KeyChainWrapper .m and .h to project directory in finder.
  5. Drag BL_KeyChainWrapper files to project and make sure Add to Targets.
  6. Import BL_KeyChainWrapper header in bridging header.
  7. Instantiate BL_KeyChainWrapper class in Swift.

If followed the above steps, and still have the error. It is probably that you didn't declare a class named BL_KeyChainWrapper in BL_KeyChainWrapper.h. Make sure in your BL_KeyChainWrapper.h, you have code like following:

@interface BL_KeyChainWrapper : BaseClass
Trowbridge answered 29/6, 2014 at 15:57 Comment(1)
Thats true, Tim Cook wouldn't tell more correctly. +1 Trouble was here - " It is probably that you didn't declare a class named BL_KeyChainWrapper in BL_KeyChainWrapper.h. Make sure in your BL_KeyChainWrapper.h, you have code like following:" Gettin olda, folks( Thanks for help!Nod
N
0

Well, after creating a test project with bridging header, I found out the following:

  1. I added .m file, Xcode proposed me to create bridging header.

  2. I added .h file, named it as class and created Obj-C class in this way.

AND:

In build settings - code generation section looks like this:

enter image description here

Bridging file located at the following path:

ProjName / BridgHeader.h

At the same level as .xcodeproj file exists.

BUT:

When I added already created Obj-C class to project and added header import in bridging header, I couldn't use it:

enter image description here

So, I guess, Xcode 6 beta 2 cannot add existing files to swift project. Did anyone face this trouble? Cause I don't want to paste all existing libraries, that I was developing for 5 years to created files.

P.S:

Bridging header:

enter image description here

Nod answered 29/6, 2014 at 15:17 Comment(1)
Try create a new blank Objective C class and see if it lets you use that.Appositive

© 2022 - 2024 — McMap. All rights reserved.