Reputation: 439
So I started work on adding Swift to an existing Objective-C framework.
The bad news is that it was rather simple to do, and appeared as if it was working. Meaning that I got the Swift code to see the obj-c classes and even build rather easily. I setup a bridging header added what I needed to it, changed the module name etc, and basically everything was working fine.
Later on I realized a few things.
Firstly, you're not supposed to have a bridging header in a framework. In fact I tried with a test project and it wouldn't let me. But someone in my actual project it allowed it.
It definitely starts cocking things up. I think because it seems to include the bridging header in the Swift generated header or maybe something else with how it imports the umbrella header. I get the simplicity of having the swift automatically use the Umbrella header and nothing else but I need another header for several reasons.
There are several problems I face in this scenario.
External targets can't load this framework using @import
. And I can't import the framework's bridging header directly either. Meaning that I can't access the Swift code from another target. I wrote an accessor class and in this case it's not a big deal. Until I realized that includes a test-case target, so I can't effectively test this code without some sort of test implementation that would be in the framework target. Not even a swift test in my test target can access the Swift.
So is there any way to do this? TL:DR "Can I have a mixed Swift/Obj-c framework that has its Swift + Obj-c accessibly externally and keep some of its obj-c private?"
Upvotes: 10
Views: 2042
Reputation: 91
I solved it.
I add public to class and protocol, so that I can access swift code in objective-c
Upvotes: 0