In addition to all of these benefits, Apple made it very easy for us to create frameworks within Xcode.
Just go onto “File -> New -> Target” and choose Cocoa Touch Framework, as shown below.
Your new framework will be displayed in the target list.
Here I have also created the unit test target for my framework.
Creating a framework in XcodeYou may want you framework to depend on another one.
For example your CustomerAccount framework may need the Network framework for all network management.
To make a framework depend on another one, you will need to check the target scheme.
In the build tab, add the module.
You will need to add this module in the build phases of the parent target too.
Make a framework depend on another one, by changing target scheme and build phases“What frameworks should I define ?”That’s an interesting question, and I think it can have multiple answers.
On the project I am working on, we chose to divide modules into two different categories :Feature modules : Modules that represent a feature of your app.
For example, you could create a module Account for your customer account part.
Kit modules : Modules that represent a technical part of your app.
You could have for instance a Network modules which handles the networking layer, a UIComponent module representing the UI elements of your app, a Localization module for your wordings… You can eventually create a Core module for everything that is connected to many parts of your application and is too hard to isolate.
If you have a local database, maybe a Storage module could be convenient to handle the database requests.
A feature module should obviously import one or more kit modules.
A Kit module should NOT import a feature module.
And a feature module should not import another feature module.
“Creating frameworks is so helpful and easy, what’s hiding behind it ?”Yes, it is very helpful and it can be easy to divide your app into frameworks, but some cases can get you into trouble.
Here is a short list of problems that I have encountered during the modularization of the app I am currently working on :Handle links between different modulesAvoid cyclic dependencies between modulesChoose where to develop a feature that is shared across several modulesHandle images between all different bundlesAnd the most difficult one : handle exportation into frameworks of an existing massive app which already has many dependenciesI will come across all these problems in detail in another medium post, because some cases need a concrete example.
“ What can we say in a few words to conclude ?.“In conclusion, my feedback on this modularization process that I came across on my project is pretty clear.
Frameworks are useful, they allow to have a decent architecture, and I really prefer to develop on this project since it has started to become modularized.
However, even though it has many advantages, this process can lead to some complicated situations and you have to be careful when dealing with modules.
Certainly, the sooner you start to modularize your application, the better.
It is more difficult to try to modularize an existing app, and it gets even harder if it’s a big app.
So think about it when building a new iOS app !.