Modulate a large iOS application with CocoaPods

Inspired by the blogpost Hubspot , I split my iOS project into one main project and several subprojects that are added to the main project using CocoaPods.

I have one main project and several subprojects (each in a separate git repository and podspec file). The advantage is that each subproject can be compiled, launched and tested on it. This approach works well, except that for global objects such as static strings, global protocols, base classes between subprojects (for example, SomeProtocol.h, constants.h), common parameters are used. I defined static lines, protocols, and base classes in the main project and created a pod specification in the main project, which includes global elements that are added to the child file of the project project.

Children's projects are compiled and run using this approach, but the main project is not compiled, since each pod subproject will include files such as

#import <SomeProtocol.h> #import <constants.h> 

that (although part of the main project) cannot be found when individual module libraries are compiled.

Is there a best practice for splitting large iOS projects into several smaller ones?

+7
ios objective-c xcode cocoapods
source share
4 answers

Is there a best practice for splitting large iOS projects into several smaller ones?

Absolutely! You have two options: libraries and frameworks. Typically, each library or framework will be its own project and will live in the workspace shared by the application, using them. Schemas will be used to create these projects as application dependencies.

This more or less describes what you would like to do: Static libraries in Xcode

Note that for your static library purposes, SKIP_INSTALL should be set to YES. Otherwise, you will have problems archiving the application.

Schemas seem to be a blind spot for many developers, but they are very important for understanding your tools and scaling up your workflow. It is so important that Apple has a WWDC session on schemes in 2011 , and then repeated it almost word for word, next year

static strings, global protocols, base classes between subprojects

Static strings should be pretty simple - use NSLocalizedString and then the values ​​are loaded by the application using the library.

I'm not sure what you mean by "global protocols." "Sharing global elements," although it doesn't sound so good. Something you generally want to avoid.

Base classes will go into their own library or structure, and other things that use them will depend on them. If libraries B and C used FooController as a base class, FooController would go to library A, with which B and C would contact.

+4
source share

Do you get duplicate characters or errors that override these classes? This is my guess about what is happening. I will lend my thoughts as if that is so.

I am working on a large project that uses the same approach, although our project is slightly different. In fact, we started with one application, and then began to create other applications that have the same functionality, so these common things were divided into our own project. Think of network code, custom alerts, custom navigation bars, etc.

From what you described, it sounds like your global elements, such as strings, constants, base classes, etc., belong to your own project, which, however that may be, but without its own project. Is it possible to break these objects into another repo and allow coco-codes to resolve dependencies? This is what we do with our project - everything that is used in more than one place is included in the overall project and is included through cocoapods.

My hunch about what is happening is that you include them (allow them in the usual way) in your main project (allow this main one) without coco-capo, then subproject A has a dependency on β€œcommon”, so cocoapods brings in common with him when he gets pulled into the main one.

Something else useful that you may not have learned yet is that you can pull all of your pods from a local drive, rather than pasting through Git. In your podfile it will look something like this:

 pod 'common', :path => '~/dev/common' 
+3
source share

Perhaps you need a generic β€œBase” Pod where you put the generic code SomeProtocol.h , constants.h .

This basic Pod will be a necessary dependency for all your other Pods like this library for these other libraries.

+1
source share

Do you have ever smaller projects in the build phases / goal dependencies?

0
source share

All Articles