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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27655705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:25:11  来源:igfitidea点击:

Can't find the swift file in framework header

xcodeswiftframeworks

提问by dickfala

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.

我曾与发布问题在Objective-C“创建框架”之前。它被解决了。

But I'm trying to create framework with swift.

但我正在尝试快速创建框架。

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

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

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

为@Jerome L

enter image description here

在此处输入图片说明

回答by Jér?me

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:

所以我想在你的情况下 ti 会是这样的:

#import <MyFramewordSwift/MyUtility-Swift.h> 

You can find more details here

您可以在此处找到更多详细信息

回答by bolnad

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 publicin 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.

我遇到了同样的问题。我有一个全 swift 项目并且正在制作一个纯粹的 swift 框架。为了在同一个项目文件中获得目标以查看我框架中的类,我需要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.htmlbut is a bit buried. If you scroll down to the section called Importing Code from Within the Same Framework Targetit 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 修饰符的声明才会出现在为框架目标生成的标头中。