1. Basic preparation

Summary scenario:

  • New Swift function module for existing Objective-C projects
  • Swift call Objective – C
  • Objective – C call Swift
  • Existing Objective-C projects access Swift’s third-party POD library

Two. Access start

New Swift function module for existing Objective-C projects

When we create a new Swift file in our ObjC project or when we create an ObjC file in our Swift project, Xcode will automatically create an Objective-C bridging header file for you (of course we can create it manually). *** Your project is ready for Swift calls to Objc when you have completed the operations shown in Figures 1 through 3. H Because the name of the project is objc_swift, it will automatically be [objc_swift-bridge-header. h] (Note that if there is a space “” or hyphens “-” in the project name, Use the underscore “_” instead.



Swift calls the Objective-C process




Objective – C call Swift

1. After creating Bridging -header. h, then Command+B builds an iOS project, the hidden files “project name -swift.h” are automatically generated.

2. To use the Swift content of the project, simply import the “project name -swift. h” file into any OC file. You can hide the file in PCH #import “project name-swift.h” (note that the imported name contains Swift in uppercase)

3. Verify that the file is successfully added: Command+ Click the file. If the content of the hidden file is displayed, the file is successfully added











Existing Objective-C projects access Swift’s third-party POD library

Open the pod file

Based on the flow above, add a new line use_frameworks at the head of the POD file! Then open the terminal to install and update the third party library for the project pod Install