I have created a new swift lib pod using the command : pod lib create MixSwiftObjectiveC found from https://guides.cocoapods.org/making/using-pod-lib-create.html
In this pod lib I need to use a code that's written in Objective-C. If I would have a separate "normal" project I would just include the import in the header file …-Bridging-Header.h. Is there an equivalent for a pod lib? Can Swift and Objective-C be mixed inside a pod lib?
As an example I've created this github: https://github.com/crarau/MixSwiftObjectiveC In order to run the example you'll need XCode Version 7.0 beta 6 and Swift 2.0
Thanks for your help!
I confirmed a working solution, here is how it works:
public
. You may need to consult the documentationsource_files
in your podspec file. Xcode automatically creates an umbrella header for your framework when you create a framework project. If your framework name isNVMDummy
, the header isNVMDummy.h
.Test your pod lib. I created a demo app, added my pod lib and in my
ViewController.m
, I did the following:The demo app works, so I conclude it works.
Here's the demo: https://github.com/axl411/TestNVMDummy
In your
.podspec
you should have something like:s.source_files = 'MixSwiftObjectiveC/Classes/*'
MixSwiftObjectiveC/Classes/
directory folder in the finder to be sure and put your files (objc and swift)Example..
folder and do apod install
(as you should have aPodfile
under yourExample..
folder that has yourMixSwiftObjectiveC
pod)This is actually pretty straight forward in cocoapod. you just need to define these lines in the .podspec file.
"s.public_header_files" automatically create an umbrella header that serves the purpose of the bridging header as well. That's it you should be able to use ObjC classes inside swift classes.
You can also use swift classes in ObjC. you just need to import -swift header in your ObjC file.
As long as the dependency is one way, you would not face any issues.