Upon reviewing the issue, I believe the linking between Swift and Objective-C should be straightforward, given that the Objective-C package has a good umbrella header file. A bridging header should have been automatically generated during the project setup, allowing you to import the Objective-C file into Swift.
Assuming your project language is Swift, and you're aiming to integrate an existing Objective-C package, you can refer to Apple's documentation for more details on importing objectives-c frameworks: Using Frameworks in Swift.
Here are a couple of things to check and consider:
- Ensure that the bridging header file is indeed generated and complied correctly. You can check this in Build Phases, under Headers Search Paths.
- Double-check that the protocol you are trying to access is included in the Objective-C umbrella header. Alternatively, you could create a new .swift file that just imports the necessary headers and exposes the protocol to Swift.
- I noticed that there doesn’t seem to be a target set up to run the example or test the ‘Calculation()’ function. You could add a quick playground or a test target to verify that everything is working correctly after including the framework.
In this case, it seems like the recommendation works, or I don't see the issue as just adding the import from the external module that contains the protocol will allow you to compile the framework; however, there is no target to run it in this case on the project you shared, nor is there a way to test the result of Calculation().printInt(). Could you please share the error messages or any specific compilation problems you are encountering? Additionally, a screenshot of the Xcode project setup could be invaluable.
import Foundation
import ObjCPackage //<—— Added
class SwiftCalci {
func doSomething() {
Calculation().printInt() // This gives compilation error. Method belongs to ObjCPackage-NiceLogs protocol
Calculation().helloWorld() // This compiles fine. Method belongs to InternalProtocol
}
}
But you should also fulfill the requirements of the protocol:
@implementation Calculation
- (void)printInt {
NSLog(@"Here it is: %d", [MathsUtilities getHardcodedInt]);
}
- (void)helloWorld {
NSLog(@"Hello World");
}
A few notes. Since you are using an ObjC package, create a Package.swift file if it does not exist already and register your ObjC headers as public. It seems like you already added a Package.swift file. Hopefully, with posting in the forums, you can provide other developers who consume and create Objective-C frameworks to share their experiences and expertise in this thread.