Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find the swift file in framework header

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:

enter image description hereenter image description here

Have anyone know how to import the file in my custom framework?

thank you very much.

============== edit ===========

for @Jerome L

enter image description here

like image 873
dickfala Avatar asked Dec 26 '14 10:12

dickfala


People also ask

Does Swift have header files?

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.

How do I create a header file in Swift?

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.


2 Answers

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.

like image 83
bolnad Avatar answered Sep 23 '22 01:09

bolnad


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

like image 28
Jérôme Avatar answered Sep 23 '22 01:09

Jérôme