I have a set of swift code which I need to package into a framework and distribute to third parties, so they can bundle it into their iOS applications.
My code depends on RxSwift.
If one of the third party applications also depends on RxSwift, and their version is not the same as my version, what happens here?
A) How do I create a swift framework that depends on another swift framework
B) What happens if there's another copy of said swift framework bundled in the app with a different version.
C) Are there any other options I have? I'm quite happy to compile the RxSwift source code into my framework if that helps
Related
I've a SDK in Swift 5.1 which our customer would like to distribute (sell) as a compiled SDK instead of giving its sources.
Unfortunately this SDK depends on some third party libraries, integrated using CocoaPods (Alamofire, RealmSwift, ReachabilitySwift, etc...). I know you should avoid having third party dependencies in your frameworks/libraries, but unfortunately we started working on this project after another agency started it. This SDK is actually a cocoapod's Pod, but it's not a compiled pod.
What is the best approach in order to distribute this SDK as a compiled SDK (in order to avoid giving source files to the final consumers who'll buy it) ?
As far as i've understood, if you compile your sdk with third party dependency, you must be sure the app that will use the same libraries with the same public apis as the one used by the compiled sdk, otherwise the app will crash at runtime. The only way to do so, as far as I understand, is to specify a very strict version of each third party dependency in the compiled sdk podspec. For example, Alamofire, '~> 4.2.0'. But I don't like this approach because this way the app can't use a newer version of Alamofire (or the other dependencies), only because the compiled sdk has been compiled with that version.
I'm creating an XCFramework, then a podspec with that XCFramework vendored as vendored_framework (using CocoaPods 1.9.0-beta2 which is the only one that currently supports XCFrameworks as vendored_framework).
I tried many different approaches, like trying to build the compiled sdk as static libraries and linking it's third party dependencies as static libraries too, but in this case when using it in the app, along with the same dependencies (e.g. Alamofire), i see in the console some "Class X is implemented in both Y and Z. Which one to use is undefined" (where Y and Z are the sdk and the app).
Have you any suggestion? How would you do that ?
Thank you!
When you say For example, Alamofire, '~> 4.2.0'. But I don't like this approach because this way the app can't use a newer version of Alamofire (or the other dependencies), only because the compiled sdk has been compiled with that version. I don't think you understood the concept of compiled SDK... When you package the SDK it will be static, so it doesn't matter the possibility of newer third-party dependencies, to update the SDK you need to release a new version to the customer, so you can upload when necessary... The customer isn't able to update the SDK by himself, not at all.
(should be a comment but too big for it)
I am trying to build a Cocoa Touch Framework written in Swift language.
There are cases where we need to use third party frameworks.
What I'd like to do is package an iOS framework (could be a Swift-framework, could be an Objective-C framework) inside another iOS framework (a Swift-framework) to hide the 3rd-party software dependencies and also hide the 3rd-party APIs.
Could anyone help with a step by step? I am using Xcode 9.2.
Recently started work on an iOS project, written in swift and objective-c. As of now, we have a monolithic repo. Now we are focusing on creating few frameworks so that we can reuse same framework across multiple apps. I would like to know your opinion on below points.
If I add framework.xcodeproj in my client app project, I'm able to access the framework's public entities after writing the import statement. My concern is every time I build by client app project, this framework.xcodeproj is also compiling though its has not changed since last build nor it is dependent on any other framework.
If I add framework by adding it as framework.framework and make its entry into embed framework, I can access the public entities of the framework. What's alarming in this case is that whenever I change the code of framework I need to update the framework in the client app project too.
Is there any way to include framework in client app project where I can access the public entities and it does not get build every time I build client app project ?
It's absolutely fine if framework get's build when its code is updated.
I have used Visual studio in past which let me build my client project without building dependent projects if there is not code change in dependent projects.
If the framework is build every time you build your app, depends on the type of the framework:
There are Cocoa Touch Static Libraries and Cocoa Touch Frameworks.
Cocoa Touch Frameworks
They are always open-source and will be built just like your app. (So Xcode will sometimes compile it, when you run your app and always after you cleaned the project.) Frameworks only support iOS 8 and newer, but you can use Swift and Objective-C in the framework.
Cocoa Touch Static Libraries
As the name says, they are static. So they are already compiled, when you import them to your project. You can share them with others without showing them your code. Note that Static Libraries currently don't support Swift. You will have to use Objective-C within the library. The app itself can still be written in Swift.
Conclusion
If you don't mind using Objective-C, Static Libraries seem to fit your requirement, that the framework should only be built once.
But since I love Swift, I would personally recommend you to use frameworks (if you don't mind that others that use the framework can see your code). My experience showed, that it's not a big problem, that the framework is built sometimes.
AddThis wrote a good blog post about deciding whether to use Static Libraries or Frameworks.
Cocoa Touch Static Library vs. Cocoa Touch Framework
I'm a novice on XCode and I'm making an iOS Framework with Swift2, including 3rd party libraries(*.a) and frameworks.
I want to provide it as API to others, but I also want to hide the 3rd party libs and frameworks files from my framework distribution files because they are private.
Therefore I just want to open API interfaces and classes I defined.
Is it possible? How to configure my build options?
You can do that but there are some things you need to consider:
You cannot embed one framework into another one. That means if you do not have the sources to a particular framework you have to ship it alongside your own framework. If you have the sources you may consider compiling them into your framework directly.
Depending on the sources that you use in the framework you might have to do some post processing of the framework to obfuscate private headers etc. For example, if you use Objective-C or C code alongside Swift you definitely need to do some post processing of your *.framework file to hide any API that you want to keep private.
If you use Swift code in your framework please be aware that your framework can only be used by someone with the same Swift compiler version due to the absence of an ABI. That means binaries produced by one compiler version have a high likelihood of being incompatible to a newer version of the compiler.
Static linked libraries can be linked and therefore "merged" into your framework binary directly. You just need to make sure that you have a compatible binary for the architecture you want to target, e.g., you cannot use a static linked library that was build for simulator and link it against your framework that you want to build for the actual iOS device.
If you use Swift in your framework, the users of your framework need to include the Swift dylib libraries in their app bundle - either by using Swift in the app or by enabling the Embedded Content Contains Swift Code build setting.
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?
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.)