Swift and OC mixing and SwiftOC Mixing

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.