Not able to access public swift class through framework

半城伤御伤魂 提交于 2019-12-21 04:36:04

问题


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?


回答1:


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

  2. 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. Now your framework is linked with your app project. You will need to import your framework in your app's source code.

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




回答2:


Did you add MessagesViewController.swift to the Target inside the original Project?

To check it just open the original project, select MessagesViewController.swift and take a look at the right sidebar (Target Membership section).




回答3:


I had this problem, and I fixed mine by going to my framework and adding target membership to Tests and UITests:

Strange fix, but I guess it works! 🤷‍♂️




回答4:


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



来源:https://stackoverflow.com/questions/37138815/not-able-to-access-public-swift-class-through-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!