Recently, I intend to do project componentization, so I must first lay a solid foundation and make my own framework! Company project encounter TableView and CollectionView no data situation, all kinds of no data view code copy to copy, very sad! This framework does lists with no data views!

1. Create the project by selecting iOS->Cocoa Touch Framework.

1.1 Select platform, search framework, here I choose iOS platform

1.2 Set the name language and other information, this is similar to creating a project

1.3 Xcode automatically generates a header file with the same name as the Framework

2. Create or drag code and resource files to the framework to complete the purpose functions of the Framework

2.1 Write and drag functional code

2.2 Write the exposed header file to the framework header file with the same name

3. Perform the corresponding configuration

3.1 Selecting the Framework type

3.2 To select the exposed header file, go to public –> Expose

4. Other configuration related to the project

If Dead Code Stripping under Link in 4.1 Build Settings is set to NO, Dead Code Stripping is not performed.

In 4.2 Build Settings, set Link With Standard Libraries under Link to NO: avoid duplicate links

Set Build Active Architecture Only to NO in 4.3 Build Settings. If set to YES, Only the framework of the current machine will be generated during the compilation. After setting it to NO, it is found that the generated framework compiled with the emulator contains both x86_64 and I386 architectures. Exclude Any iOS Simulator SDK in Release mode in Excluded Architectures. Because xcode12 generates an emulator version static library that contains an extra ARM64 architecture, which prevents later emulator versions from merging with the real version, this setting will allow emulator versions to have no ARM64 architecture.

5. Build configuration packaging

5.1 Configuring the debug-release build environment

5.2 Finding the Framework File

5.3 Viewing the Framework File Structure

6. Import configuration of the main project

6.1 Configure the Framework Embed attribute

6.2 Configuring the Other Link Flag of the Main Project

7, terminal merge real machine and simulator framework

Find the path where the framework will reside after the Build, and run the following command.

lipo -create Release-iphoneos/ListEmptyDataStyle.framework/ListEmptyDataStyle Release-iphonesimulator/ListEmptyDataStyle.framework/ListEmptyDataStyle -output FatFile/ListEmptyDataStyle

8, climb pit tips

8.1 to understand the dynamic library and static library: www.jianshu.com/p/4e0fd0214…

8.2 Since the insertion of dynamic libraries is not allowed until iOS8, most online tutorials select Static Library when McHo-type is selected. However, a static library and the static framework cannot access the resource images in the library. So if the framework you created wants to access the resource files in the library, it must be a dynamic library.

8.3 Self-building dynamic Library After manually dragging a project, you must select the Embed option; otherwise, the project will crash when started.

8.4 Objects associated with the static library cannot be observed using KVO and do not trigger the KVO callback method.