Teach you how to create iOS multi-project joint compilation in WorkSpace mode

In brief

For iOS developers, they are used to using a project development, which is also a normal operation of every iOS developer, but whenever we finish a project and develop another project, we will find that we encapsulate the network framework class , HHKit, etc. will be re-integrated into the new project, which will waste a lot of development time and do a lot of useless work. In order to avoid this situation, you might as well try to develop multiple projects in one workspace. The advantage of this method of creating projects is plug and play, which greatly reduces development time.

Screenshot of the final realization of multiple projects

Since this project uses more third-party SDKs, cocoapods is used for management, and I personally recommend using cocoapods. Of course, multi-project compilation can also be managed without cocoapods. The HHKit class includes the UIKit class and its own encapsulated UI class. The HHNetworking class is a network request class, and the HHSecurityNetwork class is a network encryption request class.
The main project JTDOASystem is independent of the other three libraries, but can call all public methods of the other three libraries
Sample screenshot_1

Implementation steps

One, create a static library of .framework

1. The static library directory structure is as follows
Sample screenshot_2

Create HHNetworking, and the HHSecurityNetwork static library method is the same as above.
2. The header files of all classes in the HHKit library should be cited in HHKit.h, as shown in the figureSample screenshot_3

3. The .h of all classes in the HHKit library should be placed in targets->Build Setting->Headers->Public, if not placed here, other projects cannot reference the classes and methods in the HHKit library, HHKit library Your own classes can be placed in Private
Sample screenshot_4

2. Manage the main project and static library

1. In the main project JTDOASystem, at the same time introduce HHNetworking, HHSecurityNetwork, HHKit's .codeproj, it is best to put these 4 .xodeproj projects on the level, easy to view the code. In addition, the shortcut key of the file is introduced: command+option+A

Third, the main project and static library use cocoaPods management

1. First, the terminal compiles PodFile, and PodFile is compiled as follows: the main project and all framework libraries are managed by cocoaPods
Sample screenshot_5

2. Use the terminal to cd the project path, and then pod install or pod update.
3. Compile the framework static library separately, select the static library, and click the triangle arrow to run it.
Sample screenshot_6

4. Add static library to main project, directory targets->Build Phases->Link Binary With Libraries, as shown in the figure
Sample screenshot_7

5. The main project creates .pch, and associates the third-party library referenced by the static library cocoaPods, as shown in the figure:Sample screenshot_8

6. Run the main project, the main project can be run at this time, if everything goes well, it can run successfully, the main project can smoothly reference the static library and the classes and methods of the third-party SDK.

Four, matters needing attention

1. If there is a category in the static library, you need to add the parameter -ObjC or -all_load (this -all_load is used with caution) in Other Linker Flags in the project configuration using the static library.Sample screenshot_9

Five, summary

At this point, you are done. If you have any questions, please feel free to leave a message!
During the integration or compilation process, you will definitely encounter various problems. Welcome everyone to discuss and make progress together.
My contact information is QQ: 1191092524. Finally, I wish you all no bugs in the code! ! !

Guess you like

Origin blog.csdn.net/gjm_123/article/details/90485534