IOS
Frameworks
Framework with dependencies
9 min
let's say we have two frameworks calcengine and core , and we need to include calcengine framework inside core as dependency there are multiple methods and some of them are described below manual integration there are multiple ways to add calcengine framework to a core framework manually as source code if we have code of both frameworks we can include the dependency framework directly to the code of the main framework it can be included as gitsubmodule as well as xcframework we can also add calcengine to the source code of core by dragging calcengine xcframework to the frameworks and libraries section in core target settings as hidden dependency procedure for adding calcengine as hidden dependency of core is same as adding is as xcframework the only difference is that we cannot simply import calcengine instead, we need to use @implementationonly import to hide calcengine from swiftinterface file and objective c headers limitation the limitation of this approach is that we cannot use any types, classes or conform to protocols from calcengine in public types/methods/classes/protocols of core framework this is enforced by the compiler also, @testable import core used in unit tests can behave unexpectedly @implementationonly import is not officially supported by apple! more details in framework with hidden dependencies docid\ ksakbfmwrnfwqqf1jr6go article cocoapods as dependency we can add calcengine to core podspec file and define which versions we work with pod spec new do |s| s name = 'core' s version = '1 0 0' s summary = 'core framework used inside mycompany' s description = 'core framework used inside mycompany' s homepage = 'https //mycompany com' s license = { \ type => 'mit', \ file => 'licence' } s author = { 'mycompany' => 'example\@mycompany com' } s source = { \ http => 'https //mycompany/frameworks/core/#{s version}/core zip'} s ios deployment target = '10 0' s ios vendored frameworks = 'core xcframework' s frameworks = 'uikit' s dependency 'calcengine', '>= 0 1 < 0 3' end this states that core depends on calcengine and can use any version between 0 1 and 0 3 there's also possibility to use "optimistic version indicator" > , it's also recommended by cocoapods optimistic version indicator it uses the last semantic version defined and allows updating of it but doesn't allow higher semantic version > major minor patch → allow updating of patch version but don't allow minor version update > major minor → allow patch and minor version update examples > 1 0 1 is equivalent to >= 1 0 1 combined with < 1 1 > 1 0 will match 1 0 , 1 0 1 , 1 1 , but will not 2 0 developers can provide a different version of the framework, but it must be compatible with the version defined in core podspec , otherwise it will throw an error if the developer specifies pod calcengine, '1 0' in podfile and in core podspec we have s dependency calcengine, ' > 0 1' , the developer will receive the following error specs satisfying the calcengine (= 1 0), calcengine ( > 0 1) dependency were found, but they required a higher minimum deployment target as subspec another solution that is that we can create a "parent" framework that will have subspec frameworks defined if we have a framework that offers multiple frameworks that all together are one big solution but at the same time can be used separately we can define one "parent" framework that lists all others as subspec pod spec new do |s| s name = 'mycompany' s subspec 'core' do |core| core source files = 'core xcframework' core dependency 'mycompany/calcengine' end s subspec 'calcengine' do |ce| ce source files = 'calcengine xcframework' end end more details in pod with child pods docid\ pke igfrywz62tlbxuy1f article references https //guides cocoapods org/making/specs and specs repo html#examples of specifications https //guides cocoapods org/making/specs and specs repo html#examples of specifications https //guides cocoapods org/syntax/podspec html#subspec https //guides cocoapods org/syntax/podspec html#subspec https //forums swift org/t/challenges creating an xcframework for native libraries/41600 https //forums swift org/t/challenges creating an xcframework for native libraries/41600 https //forums swift org/t/update on implementation only imports/26996/17 https //forums swift org/t/update on implementation only imports/26996/17 https //forums swift org/t/exported and fixing import visibility/9415 https //forums swift org/t/exported and fixing import visibility/9415 https //medium com/@anuragajwani/modular ios guide 60810f5a7f97 https //medium com/@anuragajwani/modular ios guide 60810f5a7f97