简体   繁体   中英

Making a mixed Objective-C & Swift Framework

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.

  1. Import private headers from inside the framework that I don't want to be public framework headers.
  2. Import the other frameworks which we are linked to and need access to the public headers of. I don't want to import these other frameworks in the umbrella header of this framework.

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?"

I solved it.

I add public to class and protocol, so that I can access swift code in objective-c

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM