How do I make a project where Swift and OC are compatible with hybrid development?

Source: Internet
Author: User

After Apple launched the swift language, many feared that OC would soon be replaced, but Apple said it would not abandon OC in 2 years. But now it's fast. Some development teams have started to develop on the basis of swift, but there are many old frameworks that have not yet been written in Swift, and some of the swift features you do not write and want to write with OC. So the class of OC is used from time to time in the swift development program, how to make the two languages seamless in a program? actually very convenient

If you are not in the Dong Platinum Blog Park See this article please click to view the original

This is a new Swift project that has been dragged directly into a svprogresshud framework

Because the swift language, the files within the same project are basically placed under the same namespace, so it is really convenient to use a method of a class in the project without importing the header file.

However, when you drag into the OC framework and want to use the method in the OC framework, you import the frame's header file to Viewcontroller.swift will error, this is not.

The solution is to create a new header file

After the build, import the framework into this file.

Next, refer to this file in the project deployment

The path in the mimic diagram is the head file under this project's folder

CMD+B mutation If the success says you're not wrong.

Then in the Viewcontroller.swift file, call this method in Swift's format

For example, write a click Method (remember not to import the header file!) Only need to write this method directly)

    Override Func Touchesbegan (touches:set<nsobject>, withevent event:uievent) {        svprogresshud.show ()    }

Click once after running

This completes the bridging between OC and Swift. The HUD indicator framework has been seamlessly linked to the SWIFT project. Subsequent if there are other OC classes then the head file is imported into this demo-bridge.h file and can be invoked elsewhere in the project using Swift's syntax (that is, point syntax). Remember here. 1. Do not call with OC syntax. 2. Do not import any header files in the swift suffix file.

If you are not in the Dong Platinum Blog Park See this article please click to view the original

Of course this article uses the environment is the newest XCode6.3 Beta2. Both the emulator and the SDK are iOS8.3. If the low version of Xcode encounters problems bridging, please upgrade or download to the latest version of development, because each version of the Swift language is fine-tuned.

How do I make a project where Swift and OC are compatible with hybrid development?

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.