Thursday, September 11, 2025
HomeiOS Developmentios - Swift extension to an ObjC class inside the identical framework

ios – Swift extension to an ObjC class inside the identical framework


My staff creates an xcframework, let’s name it MyFramework. The framework makes use of only one class as an API, additionally known as MyFramework. Till now, this framework has solely contained ObjC code. Nevertheless, we wish to add a Swift file to help some SwiftUI stuff. On this Swift file, I wish to add an extension to the MyFramework class.

In my Swift file, I’ve one thing easy, like

import SwiftUI
import UIKit

public extension MyFramework {
    func doStuff() { /// }
}

Nevertheless, this does not construct as a result of the swift file cannot discover MyFramework. I experimented with including a bridging header, which permits the framework to construct. Nevertheless, this does not appear to generate a .swiftinterface file, which suggests a check app cannot discover the doStuff() perform. In additional investigation, evidently bridging headers aren’t permitted in frameworks? I tried to manually assemble a .swiftinterface file, with no success.

I then enabled Construct Libraries for Distribution, which appears to be really useful for this example. Nevertheless, this requires that the bridging header be eliminated, which implies that the swift file cannot discover MyFramework once more. On-line studying suggests {that a} modulemap is meant to repair this, however I have already got a modulemap, which seems like

framework module MyFramework {
    umbrella header "MyFramework.h"

    export *
}

However this does not appear to have an effect on the construct in any respect. My understanding of modulemaps could also be flawed, however I believed they had been supposed to show ObjC code to Swift APPS, not essentially when constructing the framework within the first place.

Does anybody have any recommendation on how I can do that? I might resort to making a separate framework for the swift portion, however I might actually quite not try this if in any respect doable.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments