Swift2.0 (18) mixed programming with OBJECTIVE-C

Source: Internet
Author: User

    • Swift Project Mixed OBJECTIVE-C

Create a swift project:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7C/C2/wKiom1bXsLexFGl7AAD9_MjfQos724.png "title=" screen shot 2016-03-03 a.m. 11.34.16.png "alt=" Wkiom1bxslexfgl7aad9_mjfqos724.png "/>

Add the Objective-c class to your project:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7C/C0/wKioL1bXsUHghcQUAABabGQJwoY780.png "title=" screen shot 2016-03-03 a.m. 11.34.51.png "alt=" Wkiol1bxsuhghcquaababgqjwoy780.png "/>

The first add will pop up asking if you want to create a bridge header file:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7C/C2/wKiom1bXsNeDEuWVAADY62muq7Q252.png "title=" screen shot 2016-03-03 a.m. 11.35.05.png "alt=" Wkiom1bxsnedeuwvaady62muq7q252.png "/>

Click Create

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7C/C2/wKiom1bXsOeykAGUAABGC3D1DoU240.png "title=" screen shot 2016-03-03 a.m. 11.35.22.png "alt=" Wkiom1bxsoeykaguaabgc3d1dou240.png "/>

Adding attributes to the person class

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7C/C0/wKioL1bXsXHj0XTMAABuM7qdG6U373.png "title=" screen shot 2016-03-03 a.m. 11.35.37.png "alt=" Wkiol1bxsxhj0xtmaabum7qdg6u373.png "/>

Include the OC class that you want to use in the Swift project in the bridge header file

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7C/C2/wKiom1bXsRTA2R4qAAAkNUL_X2E445.png "title=" screen shot 2016-03-03 a.m. 11.35.54.png "alt=" Wkiom1bxsrta2r4qaaaknul_x2e445.png "/>

In the swift source file, you can use the person class to

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7C/C0/wKioL1bXsZvwwWOUAACFPb2M6nc246.png "title=" screen shot 2016-03-03 a.m. 11.36.22.png "alt=" Wkiol1bxszvwwwouaacfpb2m6nc246.png "/>

The bridge header files are configured in the project configuration file:

Buidling Settings, Swift Compiler, objective-c bridging Header

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7C/C2/wKiom1bXsTGBhytsAACYbu7hQNw079.png "title=" screen shot 2016-03-03 a.m. 11.36.36.png "alt=" Wkiom1bxstgbhytsaacybu7hqnw079.png "/>

    • OBJECTIVE-C Project Integrated Swift

To create a objective-c project:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7C/C2/wKiom1bXsUDwmPPSAABwdIycxBA904.png "title=" screen shot 2016-03-03 a.m. 11.36.52.png "alt=" Wkiom1bxsudwmppsaabwdiycxba904.png "/>

A swift class is created in the project:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7C/C2/wKiom1bXsVKQT_fiAABYUsSe-mE800.png "title=" screen shot 2016-03-03 a.m. 11.37.08.png "alt=" Wkiom1bxsvkqt_fiaabyusse-me800.png "/>

The first add will pop up asking if you want to create a bridge header file:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7C/C0/wKioL1bXsdrDZIcgAADYSpQItLE874.png "title=" screen shot 2016-03-03 a.m. 11.37.24.png "alt=" Wkiol1bxsdrdzicgaadyspqitle874.png "/>

Click Create

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7C/C0/wKioL1bXsemCqXTwAAA-3GJ8QL4063.png "title=" screen shot 2016-03-03 a.m. 11.37.38.png "alt=" Wkiol1bxsemcqxtwaaa-3gj8ql4063.png "/>

class to add a property:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7C/C2/wKiom1bXsY3h2M7MAABJxBK-N9A577.png "title=" screen shot 2016-03-03 a.m. 11.37.53.png "alt=" Wkiom1bxsy3h2m7maabjxbk-n9a577.png "/>

This bridge header file is not really needed to contain the

Include the header file in the objective-c source file: "Project name-swift.h"

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7C/C0/wKioL1bXshbyKz2vAAAsoirwvUI156.png "title=" screen shot 2016-03-03 a.m. 11.38.24.png "alt=" Wkiol1bxshbykz2vaaasoirwvui156.png "/>

This header file cannot be found in the project, it will be compiled once, and you can press and hold CMD to enter the view

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7C/C0/wKioL1bXsi_CObUDAACnXHyzd4Q070.png "title=" screen shot 2016-03-03 a.m. 11.38.39.png "alt=" Wkiol1bxsi_cobudaacnxhyzd4q070.png "/>

These are the leaks in the OC interface


This article is from the "Ammon" blog, make sure to keep this source http://annmeng.blog.51cto.com/3321237/1747077

Swift2.0 (18) mixed programming with OBJECTIVE-C

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.