Object-c and Swift

Source: Internet
Author: User

1. Calling Swift in the OBJECT-C project

1.1. Create a OBJECT-C project (project name for example: Yydemo) as

1.2. Create a swift Class, such as

This shows whether you need to create a header for the OC Bridge, and then we select the Create

PS: Bridge file

Unlike the SWIFT call OC, it is important to note the following

This is required by Swift to invoke the OC language and import the Object-c file into this bridge file Here we are OC invoke Swift language, so do not import the Swift file in this bridge file because it was created, Xcode also created a hidden file and this hidden file is the imperative for our OC to invoke Swift language. So what's his name? "Project Engineering name" + "-" + "Swift". HWe need to import this hidden file in OC class, although we can't see it, but it actually exists.

Calling Object-c in a 2.Swift project

2.1. Create a Swift Project

2.2 Creating a Object-c class

The same will show if you need to create a header for the OC Bridge, and then we choose Create.

2.3 Importing OC files into a bridge file

If you do not import, there will be no prompt in the swift file, and you cannot call

2.4. Create an object in the Swift file, run

Object-c and Swift

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.