Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to access public swift class through framework

Project structure

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?

like image 908
Shakti Avatar asked May 10 '16 12:05

Shakti


3 Answers

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

enter image description here

  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. enter image description here

  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.

enter image description here

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

  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.

like image 91
Peter Hornsby Avatar answered Nov 15 '22 15:11

Peter Hornsby


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

like image 40
Luca Angeletti Avatar answered Nov 15 '22 17:11

Luca Angeletti


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

enter image description here

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

like image 37
George Avatar answered Nov 15 '22 16:11

George