I'm trying to create asimple framework for testing with swift.
I had post the question in objective-c with "create the framework" before. It was resolved.
But I'm trying to create framework with swift.
I encounter the problem. I can't import the MyUtility file in header file.
like below:
Have anyone know how to import the file in my custom framework?
thank you very much.
============== edit ===========
for @Jerome L
The easiest way to expose your Swift code to Objective-C is by importing the Swift Bridging Header file (ProjectName-Swift. h, which is automatically generated by Xcode) from the Precompiled Header file.
Import Code Within an App Target h" . Alternatively, you can create a bridging header yourself by choosing File > New > File > [operating system] > Source > Header File.
I ran into the same issue. I have an all swift project and am making a pure swift framework. In order to get the target in the same project file to see the classes in my framework, I needed to explicitly add the modifier
public
in front of my class declaration and in front of any method that I wanted to be accessible. Here is an example of one of the classes.
private let _sharedInstance = SomeManager()
public class SomeManager: NSObject {
//MARK: - Singleton instance
public class var sharedManager : SomeManager {
return _sharedInstance
}
public func outwardFacingMethod()-> Void {
internalMethod()
}
private func internalMethod()-> Void {
}
}
The documentation in this link states here but is a bit buried. If you scroll down to the section called Importing Code from Within the Same Framework Target it says
Because the generated header for a framework target is part of the framework’s public interface, only declarations marked with the public modifier appears in the generated header for a framework target.
In order to import Swift in objective C, you need to use the following syntax:
#import <ProductName/ProductModuleName-Swift.h>
So I guess in your case ti would be something like:
#import <MyFramewordSwift/MyUtility-Swift.h>
You can find more details here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With