Swift and OC mixing and SwiftOC Mixing
Swift is quite popular when it comes out, but there are still many third-party libraries that do not support Swift. I personally feel that Swift still has a long way to go.
And even the founders of Swift have recently left apple .........
What should I do if I use third-party things in Swift? In fact, it is very simple. Xcode will automatically create a bridge file for you to connect Swift and OC languages, the same is true for using Swift in OC.
In fact, the steps are the same,
First: connect OC in Swift
Steps:
After creating an OC class, Xcode will automatically prompt you if you want to create a link file for Swift and OC. Click create, then you will find that there will be an additional header file starting with the project in the project, put the header file of the OC class to be used in this header file.
Method 2: Use Swift in OC
Steps:
Basically the same as above, you only need to create a new Swift class and there will also be a bridge file. However, the purpose of this bridge file is to enable Swift to use the OC class, it is not intended for OC to use the Swift class.
What really works with the Swift class in the OC class is the following:
First:
Find the project file-> TARGETS-> Build Settings-> Packaging-> Defines Module-> YES or search for the Defines Module in Build Settings.
Second:
Find the project file-> TARGETS-> Build Settings-> Packaging-> Product Module Name, remember this field, or search for the Product Module Name in Build Settings.
Third:
Add this section in the PCH file. I don't know the position of PCH here. The role and configuration of the PCH File
# Import "the field you just remembered-swift. h"
OK, so that you can call the Swift class in the OC environment.