How can we add a framework using Git Submodule in the IOS project
When you build an iOS application in Xcode, we usually need to use some code from another project. Projects are added functions and methods to other applications. A framework included in your project gives us code of existing functions that we can reuse without needing to recreate, like we create a car without creating each one. the wheel
Adding 1 External Respository, Sub-Project and 1 Framework
In general, to use an external framework in Xcode, we need:
- Add some synchronised links to the external repository and download them. (I will illustrate later)
- add .xcodeproj (Xcode project) file from the external repo as a sub-project to our main project, in * Xcode’File Navigator *.
- Add Framework to the build phase of your project. In fact, it will be very simple, just drag and drop so you don’t need to worry, but if you still wonder or can not do it, you can check here Build an App Like Lego tutorials
Select Managing External Repositories
There are several options for you to sync a sub-project into your project.
- Git’s submodule (( https://git-scm.com/book/en/v2/Git-Tools-Submodules ))
In this post, we will add a Framework called BFWControls to our project. These steps will be very similar when you add any framework, you just need to replace BWFControls to Respository of the Framework you want. BWFControls includes functions that make it easy to create Xcode’s Interface Builder.
Create Xcode Project
If you already have an Xcode Project you can skip this step. If not, you can create any of these IOS Template. Or you can Embed a Xib in a Storyboard through this article to create them.
Setup a Submodules folder
You can put Submodules code anywhere in your project, but I suggest you create a folder called Submodules for us to manage more easily. In Xcode, create a “New Group” naming them Submodules
Run Terminal and type cd to Submodules path. You can do this by directly dragging the Submodules folder from Xcode and dropping it directly into the Terminal Window, and holding down the Command key while releasing the mouse.
Add Submodule with terminal
Continue at the Terminal screen, type (or you can copy this command and paste it into the terminal)
git submodule add https://github.com/BareFeetWare/BFWControls.git
and press the Return key. 👁 In the Terminal, Git will download the BFWControls “Repo” and configure them directly to the directory you point to (here is the submodule).
In the Finder, inside the Submodules folder, and we see the BFWControls folder has been added and the BFWControls.xcodeproj file is easy to see.
Drag the BFWControls.xcodeproj file from the Finder into the Submodules folder in xcode
Add the Framework
Click on the Xibsample project file in Xcode. Select App Target in the General category. Scroll down to Embedded Binaries and press +
Xcode will display a list of available frameworks. Select BFWControls.framework (Don’t choose BFWControls Demo.app.)
Click the Add button, and run our project again. And we can easily see that the Framework has been added.
In this post, we have added a submodule to our xcode project with just a few lines of command in the terminal. We added a sub-project by dragging the BFWControls.xcodeproj file from the Finder to our Xcode project. And finally, we added the framework as an embedded binary. Reference: https://medium.com/build-an-app-like-lego/add-a-framework-to-an-ios-app-45c06e39bf23