无法通过框架访问公共Swift类 [英] Not able to access public swift class through framework

查看:70
本文介绍了无法通过框架访问公共Swift类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个项目并将其导入此框架中.当我将此框架加载到演示应用程序中时,我可以访问MyTest.swift文件中的公共类MyTest,但不能访问MessagesViewController.swift中的公共类.我想念什么吗?我们不能通过这种方式通过框架访问项目内部的文件吗?

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?

推荐答案

重构项目空间,以使您的应用程序不在框架内,然后处理应用程序与框架之间的链接文件.

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.

  1. 创建一个xcworkspace文件以包含您的所有子项目.有关更多信息,请查看下面的 Xcode工作区部分 Xcode概念文档
  1. Create a xcworkspace file to contain all of your sub-projects. For more information check out the Xcode Workspace section in the Xcode Concepts document

  1. 打开工作区文件,并将xcodeproj文件拖到项目导航"面板中,以添加您的框架和应用程序项目.在将文件作为Xcode添加时要小心,以免将一个项目放置在另一个项目中,这是您不想要的.

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

构建您的框架,然后将其链接到该应用程序项目.只要它们是公开的,这还将使所有框架文件可用于您的应用程序项目(有关更多详细信息,请参见下文).在编辑器视图中导航到FireChat-Swift应用程序项目目标,然后从框架项目中打开产品目录,并将框架文件拖到常规"选项卡的嵌入式二进制文件"部分.

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.

  1. 现在,您的框架已与您的应用程序项目链接.您将需要在应用程序的源代码中导入框架.

  1. Now your framework is linked with your app project. You will need to import your framework in your app's source code.

向您的框架中添加新文件,并记住如果您要求它们在框架之外使用(即由您的应用程序使用),则它们必须是公开的.

Add new files to your framework and remember they need to be public should you require them to be used outside of the framework - i.e. by your app.

这篇关于无法通过框架访问公共Swift类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆