This is the second day of my participation in the More text Challenge. For more details, see more text Challenge

background

As the current project is developed by OC, and the tripartite library imported through Cocopods is imported in the form of. A static library

demand

At present, we need to import a swift three-party SDK, so we need to pod a SWIFT three-party library in OC project

The problem

For swift tripartite libraries, use_frameworks! Import through the. Framework dynamic library. At present, POD in OC project is imported in the form of. A, so the following problems arise:

  • 1. If pod uses use_frameworks! , will change the original OC party library import method in the project, xcode will prompt that OC library cannot be found, need to change from #import

    to #import “xxx.h”

  • 2. If you don’t use use_frameworks! When the swift tripartite library is imported in the form of. A, an error occurs during compilation

The solution

Is there a way to integrate the Swift tripartite library without changing the original tripartite library import format? The answer is yes, that is to use the mixed way, that is, swift tripartite library does not use use_frameworks!

1. Xcode configuration

  • Set Mixed: target -> BMKD Module to YES

2. Project configuration

  • Create a. Swift file and automatically generate a bridge file when you create it

  • If the bridge file is not automatically generated,

    • Method 1: You can first delete paths in target > Build Settings > Objective-C Bridging Header, delete the created SWIFT file, and create a SWIFT file again. In this case, the swift file will be generated automatically

    • Method 2: You can also create a bridge file and configure the bridge file path in target -> Build Settings -> Objective-C Bridging Header

The following points should be noted:

  • 1) You need to make sure there is a bridge file project name -Bridging- header.h

  • 2) Ensure that there is at least one.swift file in your project

  • $(PRODUCT_NAME) $(PRODUCT_NAME) $(PRODUCT_NAME) $(PRODUCT_NAME)

  • 4) Target -> BuildSetting -> SWIFT_VERSION must be consistent with BuildSetting -> SWIFT_VERSION of swift tripartite library in POD

3. Use of Swift tripartite library

  • inProject name - Bridging - Header. HBridge file to import the required Swift tripartite libraries
@import swiftSDK;
Copy the code
  • Import the “project name-swift. h” file and the bridge file where the SWIFT tripartite library is needed
#import "project name -Swift. H" #import "Project name -Bridging- header.h"Copy the code

At this point, you can import the SWIFT tripartite library in the form of.a in the OC project without changing the original tripartite library import form