Swift and Objective-C hybrid programming, swiftobjective-c

Source: Internet
Author: User

Swift and Objective-C hybrid programming, swiftobjective-c
In the Swift project, you want to add Objective-C library support at the same time or use Objective-C programming at the same time.
Selecting the Objective-C system when adding a new file will automatically generate a file for a xx-Bridging-Header.h, and then put the Objective-C file to be referenced in the Swift project. h file # import "xxxx. h "can reference methods in OC in Swift files.


If the corresponding Bridging-Header file is not generated when you add an OC file, you can manually add one. h file, then name it xxx-Bridging-Header.h, select Swift Complier in Build Settings of the project, edit the content of the Objective-C Bridge-Header item to the newly added Bridging-Header file. Pay attention to the file path. Generally: ProjectName/ProjectName-Bridging-Header.h
Now, you can reference the OC method in Swift.

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.