在框架头中找不到swift文件

时间:2021-07-05 07:13:37

I'm trying to create asimple framework for testing with swift.

我正在尝试使用swift创建用于测试的简单框架。

I had post the question in objective-c with "create the framework" before. It was resolved.

我之前用“创建框架”在objective-c中发布了这个问题。它得到了解决。

But I'm trying to create framework with swift.

但我正在尝试用swift创建框架。

I encounter the problem. I can't import the MyUtility file in header file.

我遇到了这个问题。我无法在头文件中导入MyUtility文件。

like below:

如下:

在框架头中找不到swift文件在框架头中找不到swift文件

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

有谁知道如何在我的自定义框架中导入文件?

thank you very much.

非常感谢你。

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

==============编辑===========

for @Jerome L

为@Jerome L

在框架头中找不到swift文件

2 个解决方案

#1


10  

In order to import Swift in objective C, you need to use the following syntax:

要在目标C中导入Swift,您需要使用以下语法:

#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

你可以在这里找到更多细节

#2


3  

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.

我遇到了同样的问题。我有一个快速的项目,我正在制作一个纯粹的快速框架。为了在同一个项目文件中获取目标以查看我的框架中的类,我需要在我的类声明前面和我想要访问的任何方法前面显式添加修饰符public。以下是其中一个类的示例。

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

文档在这里说明了https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html,但有点埋没。如果您向下滚动到名为“从同一框架目标内导入代码”的部分

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.

因为生成的框架目标标头是框架公共接口的一部分,所以只有标记为public修饰符的声明才会出现在框架目标的生成标头中。

#1


10  

In order to import Swift in objective C, you need to use the following syntax:

要在目标C中导入Swift,您需要使用以下语法:

#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

你可以在这里找到更多细节

#2


3  

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.

我遇到了同样的问题。我有一个快速的项目,我正在制作一个纯粹的快速框架。为了在同一个项目文件中获取目标以查看我的框架中的类,我需要在我的类声明前面和我想要访问的任何方法前面显式添加修饰符public。以下是其中一个类的示例。

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

文档在这里说明了https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html,但有点埋没。如果您向下滚动到名为“从同一框架目标内导入代码”的部分

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.

因为生成的框架目标标头是框架公共接口的一部分,所以只有标记为public修饰符的声明才会出现在框架目标的生成标头中。