12

I'd like to create a framework using Cocoa Touch Framework Project in Swift. However, I'm building this framework on top of another framework called RNCryptor, which is Objective-C based. I've seen various tutorials on how to create a framework in Xcode but none has covered a framework with its own dependency.

I tried to create a framework project and then using CocoaPods to manage its dependencies. However, there are errors appeared: 'Check Dependencies' Unable to run command...'

So the question is: is it possible to create a framework on top of another framework in Xcode. And if so, how?

Donn
  • 1,680
  • 14
  • 17

1 Answers1

20

Frameworks should never embed other frameworks directly. This leads to collisions if the importing project or any other framework also includes that framework. Instead, you need to tell your consumer that they also need to include your dependency. CocoaPods will do this for you automatically, so you should let it. (If you're having trouble with CocoaPods dependencies, you should ask a question about that and get it cleared up. The whole point of CocoaPods is to manage these kinds of things.)

Note that I will be releasing the Swift version of RNCryptor into beta today (or tomorrow, but I really hope today). This version bridges to ObjC and will be the preferred version going forward. (The ObjC version will continue to be available of course for projects that cannot or don't want to include Swift.)

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • Because you have high rank i will believe you know what youre talking about when you say `Frameworks should never embed other frameworks directly` because of collisions. But is there any docs on this? – Just a coder Feb 28 '16 at 10:06
  • 1
    It's a good question. As far as I know, Apple is silent in the docs on nesting frameworks except in umbrellas, which they tell you not to make (https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/CreationGuidelines.html). Apple docs never really discuss 3rdparty code. They always assume it's just you and Apple. The advice comes from years of fixing projects that tried to nest frameworks and then had conflicts. (Mac had custom frameworks long before iOS.) see also http://stackoverflow.com/questions/7365578/why-are-umbrella-frameworks-discouraged – Rob Napier Feb 28 '16 at 12:21
  • How if we don't use CocoaPods, what's the essential part to compile through my framework if I put that dependencies in the framework header file. – Lucas Huang Jun 08 '16 at 19:38
  • @LucasHuang The dependencies should be in their own framework, and the application should link both your framework and the dependency framework. – Rob Napier Jun 08 '16 at 19:46
  • I'm just wondering how I can do that without using CocoaPods. In the meanwhile, it's a closed-source framework? Any references? – Lucas Huang Jun 10 '16 at 16:36
  • The end app just includes both your framework and the dependent framework in their "Linked frameworks" list in Xcode. https://developer.apple.com/library/ios/recipes/xcode_help-project_editor/Articles/AddingaLibrarytoaTarget.html I may not understand the question; you probably want to open this as a new question rather than using comments. – Rob Napier Jun 10 '16 at 16:50
  • @RobNapier I have a dependent framework (its written in objc) and I want to use in my own framework which is in Swift. How can I do that since frameworks don't support any bridging headers? – SandeepAggarwal Jul 24 '18 at 14:07
  • @SandeepAggarwal You should open a new question for this. (Do some searching on SO first, though; it's likely been answered.) – Rob Napier Jul 24 '18 at 14:28
  • Thanks @RobNapier for replying. Unfortunately I didn't find answer to this question on SO or anywhere till now so I have asked a new question as suggested by you https://stackoverflow.com/questions/51501424/creating-swift-framework-that-depends-on-another-framework-objc – SandeepAggarwal Jul 24 '18 at 14:41