Search code examples
iosswiftcocoapodscarthage

set up a carthage/cocoapod project to distribute multiple dependencies


Sorry if these questions are basic/dumb. I haven't had to do any framework setup stuff in the past. I've just contributed to projects in the past. I want to distribute different parts of an SDK with Cocoapods and Carthage. For example,

github "MyOrg/Core" -> Has interfaces I want to use in SmallerModule.
github "MyOrg/SmallerModule" -> Has third party dependencies I do not own

Are there general rules on how to set this up? My Core project would have interfaces that SmallerModule needs access to. Should SmallerModule be a part of the Core project or should they be separate Xcode projects?

Secondly, if it is a separate project, how does SmallerModule have access to the interfaces in Core? Do I need to include it as a dependency in SmallerModule? If so, wouldn't Core be duplicated if someone tried to pull in both Core and SmallerModule since Core is a dependency for SmallerModule?


Solution

  • Should SmallerModule be a part of the Core project or should they be separate Xcode projects

    I guess it depends by the granularity of what you need to be exposed. SmallerModule might be separated or merged inside Core, remember that once you expose it, it's quite complicate coming back, eg: you might generate dependencies to other projects.

    Secondly, if it is a separate project, how does SmallerModule have access to the interfaces in Core?

    If you split the projects, SmallerModule will easily have the access to the interfaces of the Core dynamic framework, the thing you must do first is generate such framework.

    Do I need to include it as a dependency in SmallerModule

    eg: if you use Carthage as dependency manager, you should create a Cartfile inside the project SmallerModule containing this line:

    github "MyOrg/Core"

    then on SmallerModule “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”, add the following contents to the script area below the shell:

    /usr/local/bin/carthage copy-frameworks

    Add the paths to the frameworks you want to use under “Input Files”, e.g.:

    $(SRCROOT)/Carthage/Build/iOS/Core.framework

    Add the paths to the copied frameworks to the “Output Files”, e.g.:

    $(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Core.framework

    then after resolving the dependency:

    carthage update

    You will find Core.framework inside the folder ./Carthage/build/iOS/ so you may drag and drop such framework inside your SmallerModule to be able to compile it.

    wouldn't Core be duplicated if someone tried to pull in both Core and SmallerModule since Core is a dependency for SmallerModule

    Since you'll be using a dependency manager (eg: Carthage), it won't be a problem. All the dependencies will be resolved (if they link the same version eg: tag x.y.z) by the dependency manager itself during the resolution process (carthage update).

    Note that if SuperSmallerModule has to bind your SmallerModule, then assuming everything is fine, must create a Cartfile with:

    github "MyOrg/SmallerModule"

    and follow the same process, also explained here.