8

I created a dynamic cocoa framework that I would like to use across my apps.

After I build the framework for an actual device, I bring it over to an app. I can only run the app on that device.

When I try to run it on a simulator, framework files are not recognized. I get error messages: 'ViewController' is unavailable: cannot find swift for declaration for this class

I tried building the framework for an iPhone 6 simulator and running the app on an iPhone 6 simulator, but the same problem persists.

How can I create/build a single framework that I can bring into any app and be able to use it on a simulator and a device?

user1107173
  • 10,334
  • 16
  • 72
  • 117
  • you can make a fat library , you can see this link : https://stackoverflow.com/a/54977145/3992606 – mohsen Mar 04 '19 at 05:29

1 Answers1

10

What you are looking to do is build a "Universal Framework". I answered a question about this here, but I will summarize the main points for you:

The reason you aren't able to compile it because the simulator runs on a different architecture than a device. Also, different iPhone models run on different architectures. You can look at this image to see what devices run on each architecture. The simulator runs on the mac arcs, which are i386 and x86. What you need to do is build for each architecture, then merge them all together through a process called "lipo".

To do this you want to set "Build Active Architectures" to NO. Then you should build your framework for a "Generic iOS Device". Then if you copy the build script from my first link, and put it as an aggregate target, this will build out each architecture and merge them into what will be your final product. This is called a FAT framework, and you can then run the command "lipo -info" in the terminal and you will see that your framework contains all architectures, which is what you want.

Community
  • 1
  • 1
arc4randall
  • 3,275
  • 3
  • 27
  • 40
  • Hi. Thanks for posting. I am using another framework called Alamofire in my framework. When I use your script, my framework does not recognize Alamofire. – user1107173 Jun 04 '16 at 04:01
  • Great script. Is it possible to build crossplatform (e.g. iOS + watchOS) framework in this way? – kelin Jun 17 '17 at 20:35
  • I think so, not sure as I still haven't made a watch extension yet. I think there may be some differences with watch, but I know you can make a universal framework that works with TVos – arc4randall Jun 19 '17 at 13:06
  • 1
    Perfectly worked for my universal framework too. Thanks – Arvin Sanmuga Rajah Mar 18 '19 at 10:06