There is a task - to make several Swift classes in the form of a compiled framework.

On a githaba there is a project that shows how to create a framework containing a swift class - https://github.com/crspybits/CocoaTouchFramework .

In the example of this project, the connection framework goes through the import of the xcode project.

I created a new swift project and added the already compiled SimpleFramework.framework from the above mentioned repository and got the error:

ViewController.swift: 12:25: 'SimpleClass' is unavailable: cannot find a Swift declaration for this class

That is, xcode does not see the SimpleClass class. What's wrong?

// // ViewController.swift // import UIKit import SimpleFramework @objc class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() var object = SimpleClass("fwe") } } 

My test project on github: https://github.com/nullproduction/TestApp

1 answer 1

In short, the situation is this: when you build a framework, it does not take into account all possible architectures. In other words, if the device is specified during the assembly, the assembly will be only under the device, if the simulator, then only under the simulator.

Accordingly, when you import a framework into an application, then the application inherits the same dependency - if the framework assembled for the device is connected to it, then the application will only work on the device. For example, your example from github works fine on the device, but gives an error when compiling to the simulator.

What to do with it?

The xcode command line toolkit includes a tool called 'lipo', which combines libraries assembled for different platforms into one. You need to compile your framework separately for the device and separately for the simulator, and then with the help of lipo merge into one. Here is a good example of how this might look. If you need more information, look for the words: universal framework