xcode 无法通过框架访问公共 swift 类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37138815/
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
Not able to access public swift class through framework
提问by Shakti
I created a project and imported it inside this framework. When i load this framework into a demo app, i am able to access the public class MyTest
inside MyTest.swift
file but not able to access the public class inside MessagesViewController.swift
. Am i missing something? Can't we access files inside a project through a framework this way?
我创建了一个项目并将其导入到这个框架中。当我将此框架加载到演示应用程序中时,我可以访问文件MyTest
内的公共类,MyTest.swift
但无法访问MessagesViewController.swift
. 我错过了什么吗?我们不能通过这种方式通过框架访问项目内部的文件吗?
采纳答案by Pete Hornsby
Restructure your project space so that you do not have your application inside your framework, then tackle linking files between the app and the framework.
重构您的项目空间,使您的应用程序不在您的框架中,然后处理应用程序和框架之间的链接文件。
- Create a xcworkspace file to contain all of your sub-projects. For more information check out the Xcode Workspacesection in the Xcode Conceptsdocument
Open the workspace file and add your framework and app projects by dragging the xcodeproj files to the "Project Navigation" panel. Be careful when adding the files as Xcode as a tendency to place one project inside another, you don't want this.
Build your framework and then link it to the the app project. This will also make all you framework files available to your app project as long as they are public(see below for more details). Navigate to the FireChat-Swift app project target in the editor view then from the frameworks project open the product directory and drag the framework file to the Embedded Binaries section of the general tab.
打开工作区文件并通过将 xcodeproj 文件拖到“项目导航”面板来添加您的框架和应用程序项目。添加文件作为 Xcode 时要小心,因为倾向于将一个项目放在另一个项目中,您不希望这样。
构建您的框架,然后将其链接到应用程序项目。这也将使您的所有框架文件可用于您的应用程序项目,只要它们是公开的(有关更多详细信息,请参见下文)。在编辑器视图中导航到 FireChat-Swift 应用程序项目目标,然后从框架项目打开产品目录并将框架文件拖到常规选项卡的嵌入式二进制文件部分。
回答by Luca Angeletti
Did you add MessagesViewController.swift
to the Target inside the original Project?
您是否添加MessagesViewController.swift
到原始项目中的目标?
To check it just open the original project, select MessagesViewController.swift
and take a look at the right sidebar (Target Membership section).
要检查它,只需打开原始项目,选择MessagesViewController.swift
并查看右侧边栏(目标成员资格部分)。
回答by George_E
回答by Ash
This can also occur as part of a bug in Xcode, though I'm not sure what causes it - possibly dragging files from another project into your library. I just fixed this by closing down and restarting Xcode, then cleaning the build folder (hold down Alt
then select the option from the Product
menu).
这也可能作为 Xcode 中错误的一部分发生,但我不确定是什么原因造成的 - 可能是将文件从另一个项目拖到您的库中。我只是通过关闭并重新启动 Xcode 来解决这个问题,然后清理构建文件夹(按住Alt
然后从Product
菜单中选择该选项)。