Swift Bridging Header and visibility of Obj-C class
bridging-header, ios, objective-c, swift, xcode6
Solution
Follow these steps:
- Create a Swift project
- Add a test class as Cocoa Class instead of .m and .h separately. Xcode prompt add bridging header.
- Import test class header in bridging header, which you already did. Should have no issue instantiate test class in Swift.
- Copy BL_KeyChainWrapper .m and .h to project directory in finder.
- Drag BL_KeyChainWrapper files to project and make sure Add to Targets.
- Import BL_KeyChainWrapper header in bridging header.
- 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
Problem
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". The list of things i've done : - Created .m file and Xcode proposed to create bridging header - Added obj-c files to project and imported them in header - In build setting provided the FULL path to bridging header file - Used Obj-C type in code... But it doesn't builds. - 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.