Can't find the swift file in framework header

2019-04-19 10:49发布

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 here enter 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

2条回答
The star\"
2楼-- · 2019-04-19 11:10

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 states this in here https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html 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 appear in the generated header for a framework target.

查看更多
地球回转人心会变
3楼-- · 2019-04-19 11:20

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

查看更多
登录 后发表回答