A more practical iOS SDK Project architecture

Source: Internet
Author: User

In SDK development, it is common to go through several processes, develop the SDK, test the SDK, deliver the SDK to the user, these things seem to be many steps, the process is tedious, and each time you modify the SDK will need to repeat the above process, adding some unnecessary operations. Of course, if we have a good project architecture at the beginning of the SDK design, we can greatly simplify the development process and improve the development efficiency, this article will take the reader step-by-step design to build a well-thought-out SDK development architecture.

Create a basic work space

Workspace This concept for a lot of people are not unfamiliar, usually use a lot of CocoaPods inside actually used to work space, specific some principles in my other blog.
Open Xcode->New->Workspace , named JSDSDKDemo

Create a directory for our workspace, because after creating a new workspace, only one workspace file will be generated for us and the directory will not be created automatically.

Create a directory in our workspace file sibling directory to hold the sub-project SubProject .

Open our JSDSDKDemo , create a new project, named JSSDKForDevelop , the project is mainly used for testing the SDK, remember to choose to add to JSDSDKDemo , it is best not to choose to automatically create a git repository

Then we use the same method to create a new name JSSDKInterfaceDemo , the project is used for the SDK users as a reference.

Add Static library dependent dependencies

Many developers have packaged the SDK and then got the relevant demo to test it, but in fact we just need to add relevant dependencies, we can directly in the demo test, only need to create dependencies for them.

Create a static library project, which JSDSDK is named, and it is obvious that the project is the main project in that workspace.

For the sake of the unity of the project, our SDK project is placed in the SubProject same level directory. To put the SDK on another git module, we can create a git project for the SDK.

Use the Add file in the way of JSDSDK adding to the JSSDKForDevelop inside, pay attention to choose Creat folder reference instead of selectingCreate groups

Select JSSDKForDevelop Project, in Build Phases - Tatget Dependencies add JSSDK dependency.

Of course, with this is not enough, we also need to Header Search Paths add the path to the SDK.

Then, we refer to the JSSDKForDevelop SDK Project's header file in the project and use, we can see the normal use, will not report the path-related errors, indicating that the dependency is not a problem.

Use a script to simplify your work

I have also written an article [IOS Static library packaging process simplification] (http://blog.csdn.net/zhouzhoujianquan/article/details/53192597).
This script has made some improvements on top of previous projects.

First JSSDK , to create a target that runs the script,New->Target

Select Cross-platform->Aggregate , named JSSDK_Build_Script

Then create a script file that is namedJSSDK_Build

For the JSSDK_Build_Script add Run Script Phase that was just created

Then configure the script path

This completes the automated compilation packaging process for the SDK.

How to use the project

First, after we have completed the development of the JSDSDK SDK-related functions inside, we can JSSDKForDevelop test the SDK-related code directly. Then run the JSSDK_Build_Script SDK to make the relevant package.

After the package is successful, JSSDKForDevelop the files are synced to JSSDKInterfaceDemo . SubProjectpackaged files that are also generated in the directory JSSDKInterfaceDemo

Run the JSSDKInterfaceDemo Test SDK related functions are normal, if normal, you can use the SDK delivery.

Divide the SDK into Git's sub-modules for management

Of course, further we can use git submodule to separate the SDK.

Add to

To add submodule to the current project, the command is as follows:

add 仓库地址 路径

Where the warehouse address refers to the sub-module warehouse address, the path refers to the sub-module is placed under the current project path.
Note: The path cannot be in/end (will cause the modification not to take effect), cannot be the existing project already has the directory (cannot shun the Clone)

When the command is completed, a file named under the current project root path is generated .gitmodules , which records the information of the submodule. Once added, add the folder that contains the submodule to the project.

Delete

Submodule's removal is a little tricky: first, you want to .gitmodules remove the configuration information from the file. Then, execute the git rm –cached command to remove the file that contains the submodule from Git.

Download the project with Submodule

When using Git clone down the project with Submodule, the initial time, the Submodule content is not automatically downloaded, at this time, only need to execute the following command:

gitsubmoduleupdate--init--recursive

In order to facilitate everyone to learn the demo, my demo did not do so, to avoid some developers can not be used immediately after the download will have some trouble.

Finally attached to the demo address for everyone to learn, the shortcomings of the hope to criticize.

A more practical iOS SDK Project architecture

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.