Swift and OC Mixed

Source: Internet
Author: User

Swift comes out more popular, but there are many third-party libraries that do not support swift, and individuals feel that Swift still has a long way to go.

And recently, even Swift's founders have left Apple ....

Join Swift for third-party things what to do, it is very simple, Xcode will automatically help you to create a bridging file to connect the two languages of Swift and OC, the same in OC with Swift also.

Actually the steps are the same,

First: Connect OC in Swift

Steps:

In the new OC class, to the last Xcode will automatically prompt to create a swift and OC link file, click Create, then you will find a project in the beginning of a header file, the use of the OC class to put the header file in this header file.

The second type: Using Swift in OC

Steps:

Basically the same as above, only need to create a new Swift class can be, there will be a bridge file, but the purpose of this bridging file is mainly to let Swift with OC class, not let OC with the Swift class.

The use of the Swift class by the OC class really works in the following points:

First:

Locate the project file->targets->build settings->packaging->defines Module->yes or search directly inside Build Settings defines Module

Second:

Locate the project file->targets->build settings->packaging->product Module Name, remember this field or search for Product directly in Build Settings Module Name

Third:

Add this paragraph in the PCH file, do not know the PCH dot here the function and configuration of the PCH file

#import "The field-swift.h you have just remembered"

OK, so you can invoke the Swift class in the OC environment.

Swift and OC Mixed

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.